package com.ymttest.business.service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mongodb.BasicDBObject;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.productdetail.DeliveryTemplateDto;
import com.ymatou.iapi.productquery.compare.TConsummer;
import com.ymatou.iapi.productquery.parameter.CatalogList.LiveProductCartBean;
import com.ymatou.iapi.productquery.parameter.CatalogList.ProductActivityCartBean;
import com.ymatou.iapi.productquery.parameter.CatalogList.ProductInCartBean;
import com.ymatou.iapi.productquery.parameter.CatalogList.ProductPropertyBean;
import com.ymatou.iapi.productquery.parameter.CurrencyExchangeRateDto;
import com.ymatou.iapi.productquery.parameter.ProductDescExtra.DescPropertyBean;
import com.ymatou.iapi.productquery.parameter.ProductDescExtra.ProductDescExtraBean;
import com.ymatou.iapi.productquery.parameter.ProductDetail.*;
import com.ymatou.iapi.productquery.parameter.ProductHistory.ProductHistoryBean;
import com.ymatou.iapi.productquery.parameter.ProductList.ProductInListBean;
import com.ymatou.iapi.productquery.parameter.SecKill.SecKillProductActivityStockBean;
import com.ymatou.iapi.productquery.parameter.SellOutActivityBean;
import com.ymatou.iapi.productquery.parameter.TopProduct.TopProductInLiveBean;
import com.ymatou.iapi.sellerproduct.service.GetSellerProductListCall;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.mongo.ActivityConfigWapper;
import com.ymttest.database.mongo.HistoryProductModelWapper;
import com.ymttest.database.mongo.jproduct.*;
import com.ymttest.database.redis.ImRedisWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ProductQueryCallService {
	public static void handlerVaildStartAndEndTime(String product, int sellerId, Map<String, Object> tgtMap, Map<String, Object> actMap) {
		if (tgtMap.containsKey("ValidStart") && actMap.containsKey("ValidStart")) {
			boolean isStartMatch = Math.abs(((Date) tgtMap.get("ValidStart")).getTime() - ((Date) actMap.get("ValidStart")).getTime()) <= 60 * 1000;
			boolean isEndMatch = Math.abs(((Date) tgtMap.get("ValidEnd")).getTime() - ((Date) actMap.get("ValidEnd")).getTime()) <= 60 * 1000;

			// 如果时间不匹配，新数据通过比较接口GetSellerProductList
			if (!isStartMatch || !isEndMatch) {
				JSONObject ret = new GetSellerProductListCall().SearchBySellerIdAndProdList(sellerId, Arrays.asList(product));
				try {
					String dateStartStr = ret.getJSONObject("Data").getJSONArray("ProductList").getJSONObject(0).getString("StartTime");
					String dateEndStr = ret.getJSONObject("Data").getJSONArray("ProductList").getJSONObject(0).getString("StartTime");
					if (!isStartMatch) {
						Date dateStart = YMTDateUtil.getDate(dateStartStr, YMTDateUtil.YMDTHMSS_STRING);
						if (Math.abs(((Date) actMap.get("ValidStart")).getTime() - dateStart.getTime()) > 60 * 1000) {
							tgtMap.remove("ValidStart");
							actMap.remove("ValidStart");
						}
					}

					if (!isEndMatch) {
						Date dateEnd = YMTDateUtil.getDate(dateEndStr, YMTDateUtil.YMDTHMSS_STRING);
						if (Math.abs(((Date) actMap.get("ValidEnd")).getTime() - dateEnd.getTime()) > 60 * 1000) {
							tgtMap.remove("ValidEnd");
							actMap.remove("ValidEnd");
						}
					}

				} catch (JSONException e) {
					e.printStackTrace();
				}

			}

			// 都含有status 且不相等，此时与当前时间比较vaildstart和end
			if (tgtMap.containsKey("Status") && actMap.containsKey("Status") && !tgtMap.get("Status").toString().equals(actMap.get("Status").toString())
					&& tgtMap.containsKey("ValidStart") && tgtMap.containsKey("ValidEnd")) {
				boolean isStartCloseNow = Math.abs(((Date) tgtMap.get("ValidStart")).getTime() - YMTDateUtil.getDate().getTime()) <= 5 * 60 * 1000;
				boolean isEndCloseNow = Math.abs(((Date) tgtMap.get("ValidEnd")).getTime() - YMTDateUtil.getDate().getTime()) <= 5 * 60 * 1000;
				if (isStartCloseNow || isEndCloseNow) {
					tgtMap.remove("Status");
					actMap.remove("Status");
				}

			}
		}
	}

	public static void updateActivityConfig(List<Integer> activityIds) throws Exception {
		ActivityConfigWapper activityConfigWapper = new ActivityConfigWapper();
		String groupName = "asdfsadfsad1";
		Map<String, Object> retInMgo = activityConfigWapper
				.getActivityConfig(groupName);

		List<BasicDBObject> updateDBObjects = new ArrayList<>();
		JSONArray ActivityIds = new JSONArray(retInMgo.get("ActivityIds")
				.toString());
		for (int i = 0; i < ActivityIds.length(); i++) {
			activityConfigWapper.update(groupName,
					MapUtil.hashMap("ActivityIds."+i, activityIds.get(i)));
		}
	}

	public static void updateActivityConfigV2(List<Integer> activityIds) throws Exception {
		ActivityConfigWapper activityConfigWapper = new ActivityConfigWapper();
		String groupName = "18点大牌日";
		Map<String, Object> retInMgo = activityConfigWapper
				.getActivityConfig(groupName);

		List<BasicDBObject> updateDBObjects = new ArrayList<>();
		JSONArray ActivityIds = new JSONArray(retInMgo.get("ActivityIds")
				.toString());
		for (int i = 0; i < ActivityIds.length(); i++) {
			activityConfigWapper.update(groupName,
					MapUtil.hashMap("ActivityIds."+i, activityIds.get(i)));
		}
	}

	public static void checkTimeStampRedisAndMongo(String productId) throws Exception {
		//mongo时间
		Map<String,Object> map = new ProductTimeStampWapper().getByProductId(productId);
		String mongoTime =new JSONObject(map).toString();
		System.out.println(mongoTime);
		//redis时间
		String redisTime = new ImRedisWapper().getproductById(productId);
		System.out.println(redisTime);
	}

	//Redis时间戳验证
	public static void checkTimeStampRedis(String productId) throws Exception {
		Map<String,Object> map = new ProductTimeStampWapper().getByProductId(productId);
		System.out.println("mongo时间：" + map);
		SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", java.util.Locale.US);
		Date cut = sdf.parse(map.get("cut").toString());
		System.out.println("long:" + cut.getTime());
		Date sut = sdf.parse(map.get("sut").toString());

		ImRedisWapper im = new ImRedisWapper();
		JSONObject ob=new JSONObject(im.getproductById(productId));
		System.out.println("redis时间:" + ob);
		Date cutRdeis = new Date(Long.parseLong(ob.get("cut").toString()));
		Date sutRdeis = new Date(Long.parseLong(ob.get("sut").toString()));
		AssertService.assertTime(cut,cutRdeis,100,"验证规格时间");
		AssertService.assertTime(sut,sutRdeis,100,"验证商品时间");
		if(map.get("lut") == null){
			Date lut = sdf.parse(map.get("lut").toString());
			Date lutRdeis = new Date(Long.parseLong(ob.get("lut").toString()));
			AssertService.assertTime(lut,lutRdeis,100,"验证直播时间");
		}
		if(map.get("aut") != null){
			Date aut = sdf.parse(map.get("aut").toString());
			Date autRdeis = new Date(Long.parseLong(ob.get("aut").toString()));
			AssertService.assertTime(aut,autRdeis,100,"验证活动时间");
		}
	}


	public static Map<String, Object> removeIgnoreKey(Map<String, Object> map) {
		map.remove("LimitNumStartTime");
		map.remove("LiveName");
		map.remove("LimitStartTime");
		map.remove("LimitNumber");
		map.remove("Weight");
		map.remove("IsFreeShipping");
		map.remove("LimitNum");
		map.remove("PicList");
		map.remove("HasTextDescription");
		map.remove("BrandName");
		map.remove("BrandEnName");
		map.remove("CommentCount");
		map.remove("Grade");
		map.remove("MainPic");

		// 新老库 图片不一致，新库需要洗数据
		if (map.containsKey("MainPicUrl") && map.get("MainPicUrl").toString().contains("http://pc1")) {
			map.put("MainPicUrl", map.get("MainPicUrl").toString().replace("http://pc1", "http://pic1"));
		}

		// 杭保
		if (map.containsKey("SKU") && map.get("SKU").toString().endsWith("1220")) {
			map.put("SKU", map.get("SKU").toString().replace("1220", ""));
		}

		// 如 isnew 为false 不比较newstart and new end
		if (map.containsKey("IsNewProduct") && !Boolean.parseBoolean(map.get("IsNewProduct").toString())) {
			map.remove("NewStartTime");
			map.remove("NewEndTime");
		}

		return map;
	}

	public static Map<String, Object> removeLiveProdIgnoreKey(Map<String, Object> map) {
		map.remove("LiveName");
		map.remove("MasterCategoryId");
		map.remove("MasterCategoryName");
		map.remove("CategoryId");
		map.remove("CategoryName");
		map.remove("ThirdCategoryId");
		map.remove("ThirdCategoryName");
		map.remove("AddTime");
		map.remove("CommentCount");

		return map;
	}

	public static Map<String, Object> removeActivityIgnoreKey(Map<String, Object> map) {
		if (map.containsKey("ActivityName") && map.get("ActivityName").toString().contains("洋物运动")) {
			map.remove("ActivityName");
		}

		if (map.containsKey("ActivityName") && map.get("ActivityName").toString().contains("生活家")) {
			map.remove("ActivityName");
		}

		map.remove("PromotionType");
		map.remove("ActivityStartTime");
		map.remove("ActivityEndTime");
		return map;
	}

	// 普通商品,多规格
	public static String getNewProduct(int sellerId, String sellerName) throws Exception {
//        JSONObject addProductBean = JsonBeanHelper.getJsonBean("com.ymatou.iapi.sellerproduct/AddNewSellerProduct/AddNewProductTpl_Tc2.json");
//        JsonBeanHelper.updateJsonBean(addProductBean, MapUtil.hashMap("UserID", sellerId,"LoginID", sellerName));
//        String pic1 = "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg";
//        String pic2 = "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg";
//        JsonBeanHelper.updateJsonBean(addProductBean.getJSONObject("Product"),MapUtil.hashMap("PictureUrl3",pic1,"PictureUrl2",pic2));
//        String productId = SellerProductCallService.addNewProduct(addProductBean).getJSONObject("Data").getString("ProductID");

		AddSellerProductRequest addSellerProductRequest = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
		String productId = ProductManagerCallServiceV3.AddSellerProduct(addSellerProductRequest);
		return productId;
    }

	private static int getProductStatus(String productId, int prodInActivityId, int liveId) throws Exception {
		ProductsWapper productsWapper = new ProductsWapper();
		Map<String, Object> productInMgo = productsWapper.getByProductId(productId);
		Date now = YMTDateUtil.getDateBeforeOrNextSecond(300);

		// 商品删除
		if (Integer.parseInt(productInMgo.get("action").toString()) == -1) {
			return -1;
		}

		// 有活动
		if (prodInActivityId > 0) {
			return 0;
		}

		// 有直播
		if (liveId > 0) {
			LiveProductsWapper liveProductsWapper = new LiveProductsWapper();
			Map<String, Object> liveProdInMgo = liveProductsWapper.getByActivityId(liveId);
			if (now.after((Date) liveProdInMgo.get("start")) && now.before((Date) liveProdInMgo.get("end")) && (Integer.parseInt(liveProdInMgo.get("status").toString()) == 1)) {
				return 0;
			} else {
				return 2;
			}
		}

		// 商品
		if (now.after((Date) productInMgo.get("start")) && now.before((Date) productInMgo.get("end"))) {
			return 0;
		} else {
			return 2;
		}

	}

	private static boolean getNewestProduct(boolean isNewProduct, Date startTime, Date endTime) {
		return isNewProduct;
	}

	public static <T, V> void compareListBean(List<V> keyList, List<T> tgtBeanList, List<T> actBeanList, String desc, Function<T, V> equalfunction,
			TConsummer<T, T, String> comparefunction) {
		Logger.verifyEquals(tgtBeanList.size(), actBeanList.size(), "期待结果数量应该相同");

		keyList.forEach(ele -> {
			T tgtBean = tgtBeanList.stream().filter(tgt -> equalfunction.apply(tgt).equals(ele)).findAny().orElse(null);
			T actBean = actBeanList.stream().filter(tgt -> equalfunction.apply(tgt).equals(ele)).findAny().orElse(null);

			Logger.verifyNotNull(tgtBean, "期待结果不该为null " + ele);
			Logger.verifyNotNull(actBean, "实际结果不该为null " + ele);

			comparefunction.accept(tgtBean, actBean, desc);

		});
	}

	// json to bean
	public static <T> T getBeanFromJson(JSONObject jsonObject, Class<T> clz) {
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
		return gson.fromJson(jsonObject.toString(), clz);
	}

	// 多物流购物车 GetCatalogListByDeliveryExtra
	// =================================================================================================================================
	public static ProductInCartBean getProductInCartForDeliveryBean(String catalogId, int delType, int prodInActivityId, int prodInNextActivityId, int liveId) throws Exception {
		ProductInCartBean productInCartForDeliveryBean = getProductInCartBean(catalogId, prodInActivityId, prodInNextActivityId, liveId);

		ProductsWapper productsWapper = new ProductsWapper();
		Map<String, Object> productMap = productsWapper.getByProductId(productInCartForDeliveryBean.getProductId());
		productInCartForDeliveryBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));
		productInCartForDeliveryBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));

		// 多物流价格计算
//		if (delType == Integer.parseInt(productMap.get("mdeliv").toString())) {
//			productInCartForDeliveryBean.setPrice(productInCartForDeliveryBean.getPrice() + Integer.parseInt(productMap.get("mflight").toString()));
//		}

		return productInCartForDeliveryBean;

	}

	public static ProductInCartBean getProductInCartForDeliveryBean(String catalogId, int delType) throws Exception {
		ProductInCartBean productInCartForDeliveryBean = getProductInCartBean(catalogId);

		ProductsWapper productsWapper = new ProductsWapper();
		Map<String, Object> productMap = productsWapper.getByProductId(productInCartForDeliveryBean.getProductId());
		productInCartForDeliveryBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));
		productInCartForDeliveryBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));

		// 多物流价格计算
//		if (delType == Integer.parseInt(productMap.get("mdeliv").toString())) {
//			productInCartForDeliveryBean.setPrice(productInCartForDeliveryBean.getPrice() + Integer.parseInt(productMap.get("mflight").toString()));
//		}

		return productInCartForDeliveryBean;

	}

	public static void compareProductInCartForDeliveryBean(ProductInCartBean tgtProductInCartForDeliveryBean, ProductInCartBean actProductInCartForDeliveryBean, String desc) {

		compareProductInCartBean(tgtProductInCartForDeliveryBean, actProductInCartForDeliveryBean, desc);

		Logger.verifyEquals(tgtProductInCartForDeliveryBean.getExtraDeliveryFee(), actProductInCartForDeliveryBean.getExtraDeliveryFee(), desc);
		Logger.verifyEquals(tgtProductInCartForDeliveryBean.getExtraDeliveryType(), actProductInCartForDeliveryBean.getExtraDeliveryType(), desc);
	}

	// 购物车 GetCatalogListByCatalogIdList
	// =================================================================================================================================
	public static ProductInCartBean getProductInCartBean(String catalogId, int prodInActivityId, int liveId) throws Exception {
		return getProductInCartBean(catalogId, prodInActivityId, 0, liveId);
	}

	public static ProductInCartBean getProductInCartBean(String catalogId) throws Exception{
		YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
		CatalogsWapper catalogsWapper = new CatalogsWapper();
		ProductsWapper productsWapper = new ProductsWapper();
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
		YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId);
		YmtCatalogsI rootYmtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(ymtCatalogsI.getRootCatalogId());
		String rootProductId = rootYmtCatalogsI.getsProductId();
		Map<String, Object> byProductId = productsWapper.getByProductId(rootProductId);

		Map<String, Object> catalogMap = catalogsWapper.getByCatalogId(catalogId);
		Logger.debug("catalogMap:" + catalogMap);
		String productId = catalogMap.get("spid").toString();

		Map<String, Object> productMap = productsWapper.getByProductId(productId);
		Logger.debug("productMap: +" +productMap);

		// 组装数据
		ProductInCartBean productInCartBean = new ProductInCartBean();
		productInCartBean.setProductId(productId);
		productInCartBean.setCatalogId(catalogId);
		productInCartBean.setProductName(productMap.get("title").toString());
		productInCartBean.setValidStart((Date) productMap.get("start"));
		productInCartBean.setValidEnd((Date) productMap.get("end"));
		productInCartBean.setBrandId(Integer.parseInt(byProductId.get("bid").toString()));
		productInCartBean.setMasterCategoryId(Integer.parseInt(byProductId.get("mcatid").toString()));
		productInCartBean.setCategoryId(Integer.parseInt(byProductId.get("scatid").toString()));
		productInCartBean.setThirdCategoryId(Integer.parseInt(byProductId.get("tcatid").toString()));
		productInCartBean.setSellerId(Integer.parseInt(productMap.get("sid").toString()));
		productInCartBean.setSellerName(productMap.get("sname").toString());
		productInCartBean.setDeliveryMethod(Integer.parseInt(byProductId.get("deliv").toString()));
		productInCartBean.setBondedArea(Integer.parseInt(productMap.get("bonded").toString()));
		productInCartBean.setFreeShipping(Double.parseDouble(productMap.get("shipping").toString()) <= 0);
		productInCartBean.setTariffType(Integer.parseInt(productMap.get("tariffy").toString()));
		productInCartBean.setLocalReturn(Integer.parseInt(productMap.get("localr").toString()));
		productInCartBean.setCatalogType(Integer.parseInt(productMap.get("ctype").toString()));
		productInCartBean.setNoReasonReturn(Boolean.parseBoolean(productMap.get("noreason").toString()));
		productInCartBean.setPspProduct(Boolean.parseBoolean(productMap.get("ispsp").toString()));
		productInCartBean.setGrouponVersion(0);
		productInCartBean.setRootUserId(Integer.parseInt(productMap.get("ruid").toString()));
		if (productMap.get("puid")==null){
			productInCartBean.setParentUserId(0);
		}else{
			productInCartBean.setParentUserId(Integer.parseInt(productMap.get("puid").toString()));
		}
		productInCartBean.setCardInfo(Integer.parseInt(productMap.get("card").toString()));
		productInCartBean.setAgentChain(productMap.get("achain").toString());

		List<DeliveryTemplateDto> deliveryTemplateList = new ArrayList<>();
		if (ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootProductId)!=null){
			List<Map> deliMaps = ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootProductId);
			deliMaps.forEach(p->{
				DeliveryTemplateDto deliveryTemplateDto = new DeliveryTemplateDto();
				deliveryTemplateDto.setDeliveryMethod(Integer.parseInt(byProductId.get("deliv").toString()));
				deliveryTemplateDto.setTemplateId(Integer.parseInt(p.get("TemplateId").toString()));
				deliveryTemplateList.add(deliveryTemplateDto);
			});
		}
		productInCartBean.setDeliveryTemplateList(deliveryTemplateList);

		CurrencyExchangeRateDto currencyExchangeRateDto = new CurrencyExchangeRateDto();
		currencyExchangeRateDto.setCurrency(productMap.get("currency").toString());
		productInCartBean.setCurrencyExchangeRate(currencyExchangeRateDto);

		productInCartBean.setProductCode(productMap.get("pcode") == null ? "" : productMap.get("pcode").toString());

		if (productMap.get("ver")!=null){
			productInCartBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));
		}else {
			productInCartBean.setVersion("0");
		}

		if (Integer.parseInt(productMap.get("status").toString())==2){
			productInCartBean.setStatus(2);
		}else if (Integer.parseInt(productMap.get("status").toString())==1){
			productInCartBean.setStatus(0);
		}

		// 主图
		JSONArray picsMgo = new JSONArray(productMap.get("pics").toString());
		productInCartBean.setMainPicUrl(picsMgo.getString(0));

		// 获取商品规格个数
		productInCartBean.setCatalogCount(catalogsWapper.getCountByProductId(productId));

		// 规格维度取值
		productInCartBean.setPreSale(Boolean.parseBoolean(catalogMap.get("presale").toString()));
		productInCartBean.setPrice(Double.parseDouble(catalogMap.get("price").toString()));
		productInCartBean.setStockNum(rootYmtCatalogsI.getiNum());
		productInCartBean.setCatalogStockNum(rootYmtCatalogsI.getiNum());

		productInCartBean.setSku(String.valueOf(catalogMap.get("sku") == null ? "" : catalogMap.get("sku").toString()));

		// 固定返回值
		productInCartBean.setWeight(0d);

		// 不用检查，前端已不使用
		productInCartBean.setLimitNumber(0);
		productInCartBean.setLimitStartTime(new Date(1900, 1, 1));

		// 多物流 自营
		productInCartBean.setOwnProduct(Integer.parseInt(productMap.get("own").toString()) == 1 ? true : false);
		productInCartBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));
		productInCartBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));

		// 属性值
		List<ProductPropertyBean> properties = new ArrayList<>();
		if (catalogMap.get("props") == null) {
			// 添加一个空的
			ProductPropertyBean productPropertyBean = new ProductPropertyBean();
			properties.add(productPropertyBean);
		} else {
			JSONArray propsAry = new JSONArray(catalogMap.get("props").toString());
			for (int i = 0; i < propsAry.length(); i++) {
				JSONObject prop = propsAry.getJSONObject(i);
				ProductPropertyBean productPropertyBean = new ProductPropertyBean();
				productPropertyBean.setPropertyName(prop.getString("name"));
				productPropertyBean.setPropertyValue(prop.getString("value"));
				productPropertyBean.setPropertyPictureUrl(prop.getString("pic"));
				properties.add(productPropertyBean);
			}

		}
		productInCartBean.setProperties(properties);
		Logger.debug("productInCartBean:"+productInCartBean);
		return productInCartBean;
	}

	/***
	 *
	 * @param catalogId
	 * @param prodInActivityId
	 *            有效 if>0
	 * @param liveId
	 *            有效 if>0
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("deprecation")
	public static ProductInCartBean getProductInCartBean(String catalogId, int prodInActivityId, int nextProdInActId, int liveId) throws Exception {
		CatalogsWapper catalogsWapper = new CatalogsWapper();
		ProductsWapper productsWapper = new ProductsWapper();

		Map<String, Object> catalogMap = catalogsWapper.getByCatalogId(catalogId);
		Logger.debug("catalogMap:" + catalogMap);
		String productId = catalogMap.get("spid").toString();

		Map<String, Object> productMap = productsWapper.getByProductId(productId);
		Logger.debug("productMap: +" +productMap);

		// 组装数据
		ProductInCartBean productInCartBean = new ProductInCartBean();
		//待确认：GlobalProductType在mongo中对应的字段 确认后再比较
//		if(productMap.get("gtype")!=null&&productMap.get("gtype").toString().length()>0) {
//			productInCartBean.setGlobalProductType(Integer.valueOf(productMap.get("gtype").toString()));
//		}
		if(productMap.get("cpic")!=null) {
			productInCartBean.setCatalogPic(productMap.get("cpic").toString());
		}
		productInCartBean.setProductId(productId);
		productInCartBean.setCatalogId(catalogId);
		productInCartBean.setProductName(productMap.get("title").toString());
		productInCartBean.setValidStart((Date) productMap.get("start"));
		productInCartBean.setValidEnd((Date) productMap.get("end"));
		productInCartBean.setBrandId(Integer.parseInt(productMap.get("bid").toString()));
		productInCartBean.setMasterCategoryId(Integer.parseInt(productMap.get("mcatid").toString()));
		productInCartBean.setCategoryId(Integer.parseInt(productMap.get("scatid").toString()));
		productInCartBean.setThirdCategoryId(Integer.parseInt(productMap.get("tcatid").toString()));
		productInCartBean.setSellerId(Integer.parseInt(productMap.get("sid").toString()));
		productInCartBean.setSellerName(productMap.get("sname").toString());
		productInCartBean.setDeliveryMethod(Integer.parseInt(productMap.get("deliv").toString()));
		productInCartBean.setBondedArea(Integer.parseInt(productMap.get("bonded").toString()));
		productInCartBean.setFreeShipping(Double.parseDouble(productMap.get("shipping").toString()) <= 0);
		productInCartBean.setTariffType(Integer.parseInt(productMap.get("tariffy").toString()));
		productInCartBean.setLocalReturn(Integer.parseInt(productMap.get("localr").toString()));
		productInCartBean.setCatalogType(Integer.parseInt(productMap.get("ctype").toString()));
		productInCartBean.setNoReasonReturn(Boolean.parseBoolean(productMap.get("noreason").toString()));
		productInCartBean.setPspProduct(Boolean.parseBoolean(productMap.get("ispsp").toString()));
		productInCartBean.setGrouponVersion(Integer.parseInt(productMap.get("goversion").toString()));

		productInCartBean.setProductCode(productMap.get("pcode") == null ? "" : productMap.get("pcode").toString());

		productInCartBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));
		productInCartBean.setStatus(getProductStatus(productId, prodInActivityId, liveId));

		// 主图
		JSONArray picsMgo = new JSONArray(productMap.get("pics").toString());
		productInCartBean.setMainPicUrl(picsMgo.getString(0));

		// 获取商品规格个数
		productInCartBean.setCatalogCount(catalogsWapper.getCountByProductId(productId));

		// 规格维度取值
		productInCartBean.setPreSale(Boolean.parseBoolean(catalogMap.get("presale").toString()));
		productInCartBean.setPrice(Double.parseDouble(catalogMap.get("price").toString()));
		productInCartBean.setStockNum(Integer.parseInt(catalogMap.get("stock").toString()));
		productInCartBean.setCatalogStockNum(Integer.parseInt(catalogMap.get("stock").toString()));

		productInCartBean.setSku(String.valueOf(catalogMap.get("sku") == null ? "" : catalogMap.get("sku").toString()));

		// 固定返回值
		productInCartBean.setWeight(0d);

		// 不用检查，前端已不使用
		productInCartBean.setLimitNumber(0);
		productInCartBean.setLimitStartTime(new Date(1900, 1, 1));

		// 多物流 自营
		productInCartBean.setOwnProduct(Integer.parseInt(productMap.get("own").toString()) == 1 ? true : false);
		productInCartBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));
		productInCartBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));

		// 属性值
		List<ProductPropertyBean> properties = new ArrayList<>();
		if (catalogMap.get("props") == null) {
			// 添加一个空的
			ProductPropertyBean productPropertyBean = new ProductPropertyBean();
			properties.add(productPropertyBean);
		} else {
			JSONArray propsAry = new JSONArray(catalogMap.get("props").toString());
			for (int i = 0; i < propsAry.length(); i++) {
				JSONObject prop = propsAry.getJSONObject(i);
				ProductPropertyBean productPropertyBean = new ProductPropertyBean();
				productPropertyBean.setPropertyName(prop.getString("name"));
				productPropertyBean.setPropertyValue(prop.getString("value"));
				productPropertyBean.setPropertyPictureUrl(prop.getString("pic"));
				properties.add(productPropertyBean);
			}

		}
		productInCartBean.setProperties(properties);

		// 有活动信息 活动库存和价格优先
		if (prodInActivityId > 0) {
			ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(prodInActivityId);
			Logger.debug("activityProductMap:"+activityProductMap);


			ProductActivityCartBean productActivityCartBean = new ProductActivityCartBean();
			productActivityCartBean.setProductInActivityId(prodInActivityId);
			productActivityCartBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
			productActivityCartBean.setActivityName(String.valueOf(activityProductMap.get("aname")));
			productActivityCartBean.setProductActivityStartTime((Date) activityProductMap.get("start"));
			productActivityCartBean.setProductActivityEndTime((Date) activityProductMap.get("end"));
			productActivityCartBean.setActivityLimitNumber(Integer.parseInt(activityProductMap.get("alimit").toString()));
			productActivityCartBean.setProductActivityLimitNumber(Integer.parseInt(activityProductMap.get("plimit").toString()));
			productActivityCartBean.setNewBuyer(Boolean.parseBoolean(activityProductMap.get("nbuyer").toString()));
			productActivityCartBean.setPromotionType(3);
			productActivityCartBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
			productActivityCartBean.setEarnest(Double.parseDouble(activityProductMap.get("earnest").toString()));
			productActivityCartBean.setEarnestDedution(Double.parseDouble(activityProductMap.get("ededution").toString()));
			productActivityCartBean.setActivityType(Integer.parseInt(activityProductMap.get("atype").toString()));

			if (activityProductMap.keySet().contains("member")) {
				productActivityCartBean.setIsMember(Boolean.parseBoolean(activityProductMap.get("member").toString()));
			} else {
				productActivityCartBean.setIsMember(false);
			}

			List<String> catalogList = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				catalogList.add(catalogsAry.getJSONObject(i).getString("cid"));

				if (catalogsAry.getJSONObject(i).getString("cid").equals(catalogId)) {
					// 活动库存和价格优先
					productInCartBean.setPrice(catalogsAry.getJSONObject(i).getDouble("price"));
					productInCartBean.setStockNum(catalogsAry.getJSONObject(i).getInt("stock"));
					productInCartBean.setActivityStockNum(catalogsAry.getJSONObject(i).getInt("stock"));
				}
			}
			productActivityCartBean.setActivityCatalogList(catalogList);

			// 填值
			productInCartBean.setProductActivity(productActivityCartBean);
			productInCartBean.setValidStart((Date) activityProductMap.get("start"));
			productInCartBean.setValidEnd((Date) activityProductMap.get("end"));

			Logger.verifyEquals(true, catalogList.contains(catalogId), "catalogid:" + catalogId + ", 该规格应在活动商品中");
		}

		// 下一场活动
		if (nextProdInActId > 0) {
			ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(nextProdInActId);

			if(Integer.parseInt(activityProductMap.get("atype").toString())!=2){
				ProductActivityCartBean productActivityCartBean = new ProductActivityCartBean();
				productActivityCartBean.setProductInActivityId(nextProdInActId);
				productActivityCartBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
				productActivityCartBean.setActivityName(String.valueOf(activityProductMap.get("aname")));
				productActivityCartBean.setProductActivityStartTime((Date) activityProductMap.get("start"));
				productActivityCartBean.setProductActivityEndTime((Date) activityProductMap.get("end"));
				productActivityCartBean.setActivityLimitNumber(Integer.parseInt(activityProductMap.get("alimit").toString()));
				productActivityCartBean.setProductActivityLimitNumber(Integer.parseInt(activityProductMap.get("plimit").toString()));
				productActivityCartBean.setNewBuyer(Boolean.parseBoolean(activityProductMap.get("nbuyer").toString()));
				productActivityCartBean.setPromotionType(3);
				productActivityCartBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
				if (activityProductMap.keySet().contains("member")) {
					productActivityCartBean.setIsMember(Boolean.parseBoolean(activityProductMap.get("member").toString()));
				} else {
					productActivityCartBean.setIsMember(false);
				}

				List<String> catalogList = new ArrayList<>();
				JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
				for (int i = 0; i < catalogsAry.length(); i++) {
					catalogList.add(catalogsAry.getJSONObject(i).getString("cid"));

					if (catalogsAry.getJSONObject(i).getString("cid").equals(catalogId)) {
						// 下一场活动库存和价格
						productInCartBean.setNextActivityPrice(catalogsAry.getJSONObject(i).getDouble("price"));
						productInCartBean.setNextActivityStock(catalogsAry.getJSONObject(i).getInt("stock"));
					}
				}
				productActivityCartBean.setActivityCatalogList(catalogList);

				// 填值
				productInCartBean.setNextActivity(productActivityCartBean);

				Logger.verifyEquals(true, catalogList.contains(catalogId), "catalogid:" + catalogId + ", 该规格应在下一场活动商品中");

			}

			}

		// 有直播信息
		if (liveId > 0) {
			LiveProductsWapper liveProductsWapper = new LiveProductsWapper();
			Map<String, Object> liveProdMap = liveProductsWapper.getByActivityId(liveId);

			LiveProductCartBean liveProductCartBean = new LiveProductCartBean();
			liveProductCartBean.setLiveId(liveId);
			// liveProductCartBean.setLiveName(String.valueOf(liveProdMap.get("name")));
			liveProductCartBean.setStartTime((Date) liveProdMap.get("start"));
			liveProductCartBean.setEndTime((Date) liveProdMap.get("end"));
			liveProductCartBean.setSellStatus(Integer.parseInt(liveProdMap.get("status").toString()));
			// 填值
			productInCartBean.setLiveProduct(liveProductCartBean);

			// 设置开始结束时间
			productInCartBean.setValidStart((Date) liveProdMap.get("start"));
			productInCartBean.setValidEnd((Date) liveProdMap.get("end"));

		}

		// new property
		// IsCurActivitySellOut 只有有当前活动，并且所以规格活动库存为0 就为true，否则为true
		if (prodInActivityId < -1) {
			ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(-1 * prodInActivityId);
			int allActivityStock = 0;
			List<Double> priceList = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				allActivityStock = allActivityStock + catalogsAry.getJSONObject(i).getInt("stock");
				Double price = catalogsAry.getJSONObject(i).getDouble("price");
				priceList.add(price);
			}

			Collections.sort(priceList);
			if (allActivityStock == 0) {
				SellOutActivityBean sellOutActivityBean = new SellOutActivityBean();
				sellOutActivityBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
				sellOutActivityBean.setActivityName(activityProductMap.get("aname").toString());
				sellOutActivityBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
				sellOutActivityBean.setActivityLevel(Integer.parseInt(activityProductMap.get("alevel").toString()));
				sellOutActivityBean.setMinPrice(priceList.get(0));
				sellOutActivityBean.setMaxPrice(priceList.get(priceList.size()-1));
				productInCartBean.setSellOutActivity(sellOutActivityBean);
			}
		}

		return productInCartBean;
	}

	// 批量检查
	public static void compareProductInCartBean(List<String> catalogIdList, List<ProductInCartBean> tgtProductInCartBeanList, List<ProductInCartBean> actProductInCartBeanList,
			String desc) {
		Logger.verifyEquals(tgtProductInCartBeanList.size(), actProductInCartBeanList.size(), "期待结果数量应该相同");

		catalogIdList.forEach(ele -> {
			ProductInCartBean tgtProductInCartBean = tgtProductInCartBeanList.stream().filter(tgt -> tgt.getCatalogId().equals(ele)).findAny().orElse(null);
			ProductInCartBean actProductInCartBean = actProductInCartBeanList.stream().filter(act -> act.getCatalogId().equals(ele)).findAny().orElse(null);

			Logger.verifyNotNull(tgtProductInCartBean, "期待结果不该为null catalogId:" + ele);
			Logger.verifyNotNull(actProductInCartBean, "实际结果不该为null catalogId:" + ele);

			compareProductInCartBean(tgtProductInCartBean, actProductInCartBean, desc);

		});

	}

	public static void compareProductInCartBean(ProductInCartBean tgtProductInCartBean, ProductInCartBean actProductInCartBean, String desc) {
		// 第一层数据对比
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtProductInCartBean);
		tgtMap.remove("Properties");
		tgtMap.remove("LiveProduct");
		tgtMap.remove("ProductActivity");
		tgtMap.remove("NextActivity");
		tgtMap.remove("SellOutActivity");
		tgtMap.remove("DeliveryTemplateList");
		tgtMap.remove("CurrencyExchangeRate");

		Map<String, Object> actMap = MapUtil.pojoToMap(actProductInCartBean);
		actMap.remove("Properties");
		actMap.remove("LiveProduct");
		actMap.remove("ProductActivity");
		actMap.remove("NextActivity");
		actMap.remove("SellOutActivity");
		actMap.remove("DeliveryTemplateList");
		actMap.remove("CurrencyExchangeRate");
		if(actMap.get("GlobalProductType")==null){
			actMap.put("GlobalProductType",0);
		};
		if(tgtMap.get("GlobalProductType")==null){
			tgtMap.put("GlobalProductType",0);
		};
		// ignore
		removeIgnoreKey(tgtMap);
		removeIgnoreKey(actMap);
		AssertService.assertResultEqual(tgtMap, actMap, desc);

		System.out.println("maptgt:"+tgtMap);
		System.out.println("mapact:"+actMap);
		// 第二层数据对比

		if (tgtProductInCartBean.getCurrencyExchangeRate()!=null){
			Logger.verifyEquals(tgtProductInCartBean.getCurrencyExchangeRate().getCurrency(),actProductInCartBean.getCurrencyExchangeRate().getCurrency(),"验证currency");
		}

		if (tgtProductInCartBean.getDeliveryTemplateList()!=null){
			List<DeliveryTemplateDto> tgtDeliveryTemplateList = tgtProductInCartBean.getDeliveryTemplateList();
			List<DeliveryTemplateDto> actDeliveryTemplateList = actProductInCartBean.getDeliveryTemplateList();
			Logger.verifyEquals(tgtDeliveryTemplateList.size(),actDeliveryTemplateList.size(),"验证模板数量应该一致");
			tgtDeliveryTemplateList.forEach(tgt->{
				DeliveryTemplateDto deliveryTemplateDto = actDeliveryTemplateList.stream().filter(act -> act.getTemplateId() == tgt.getTemplateId()).findFirst().orElse(null);
				if (deliveryTemplateDto!=null){
					Map<String, Object> tgtCatalogMap = MapUtil.pojoToMap(tgt);
					Map<String, Object> actCatalogMap = MapUtil.pojoToMap(deliveryTemplateDto);
					AssertService.assertResultEqual(tgtCatalogMap, actCatalogMap, desc);
				}
			});
		}


		// 直播
		if (tgtProductInCartBean.getLiveProduct() != null) {
			if (actProductInCartBean.getLiveProduct() == null) {
				Logger.verifyEquals(true, false, desc + ", 直播商品，应该有直播信息-LiveProduct");
			} else {
				Map<String, Object> tgtLiveMap = MapUtil.pojoToMap(tgtProductInCartBean.getLiveProduct());
				Map<String, Object> actLiveMap = MapUtil.pojoToMap(actProductInCartBean.getLiveProduct());
				AssertService.assertResultEqual(tgtLiveMap, actLiveMap, desc);
			}

		} else {
			Logger.verifyIsNull(actProductInCartBean.getLiveProduct(), desc);
		}
		// 本场活动
		if (tgtProductInCartBean.getProductActivity() != null) {
			Map<String, Object> tgtActivityMap = MapUtil.pojoToMap(tgtProductInCartBean.getProductActivity());
			tgtActivityMap.remove("ActivityCatalogList");

			if (actProductInCartBean.getProductActivity() == null) {
				Logger.verifyEquals(true, false, desc + ", 活动商品，应该有活动信息-ProductActivity");
			} else {
				Map<String, Object> actActivityMap = MapUtil.pojoToMap(actProductInCartBean.getProductActivity());
				actActivityMap.remove("ActivityCatalogList");

				AssertService.assertResultEqual(tgtActivityMap, actActivityMap, desc);

				AssertService.checkArray(tgtProductInCartBean.getProductActivity().getActivityCatalogList(), actProductInCartBean.getProductActivity().getActivityCatalogList());
			}
		} else {
			Logger.verifyIsNull(actProductInCartBean.getProductActivity(), desc);
		}

		// 下场活动
		if (tgtProductInCartBean.getNextActivity() != null) {
			Map<String, Object> tgtActivityMap = MapUtil.pojoToMap(tgtProductInCartBean.getNextActivity());
			tgtActivityMap.remove("ActivityCatalogList");

			if (actProductInCartBean.getNextActivity() == null) {
				Logger.verifyEquals(true, false, desc + ", 活动商品，应该有下一场活动信息-NextProductActivity");
			} else {
				Map<String, Object> actActivityMap = MapUtil.pojoToMap(actProductInCartBean.getNextActivity());
				actActivityMap.remove("ActivityCatalogList");

				AssertService.assertResultEqual(tgtActivityMap, actActivityMap, desc);

				AssertService.checkArray(tgtProductInCartBean.getNextActivity().getActivityCatalogList(), actProductInCartBean.getNextActivity().getActivityCatalogList());
			}
		} else {
			Logger.verifyIsNull(actProductInCartBean.getNextActivity(), desc);
		}

		// 属性比对 todo
		List<ProductPropertyBean> tgtProps = tgtProductInCartBean.getProperties();
		List<ProductPropertyBean> actProps = actProductInCartBean.getProperties();
		Logger.verifyEquals(tgtProps.size(), actProps.size(), "属性值个数比较");
		if (tgtProps.size() == 1 && tgtProps.get(0).getPropertyName() == null) {
			// 单规格
			Logger.verifyEquals(1, actProps.size(), "单规格，属性节点个数为1");
			Logger.verifyIsNull(actProps.get(0).getPropertyName(), "单规格属性为null");
			Logger.verifyIsNull(actProps.get(0).getPropertyPictureUrl(), "单规格属性为null");
			Logger.verifyIsNull(actProps.get(0).getPropertyValue(), "单规格属性为null");

		} else {
			tgtProps.forEach(ele -> {
				ProductPropertyBean actProp = actProps.stream().filter(y -> y.getPropertyName().equals(ele.getPropertyName())).findFirst().orElse(null);
				Map<String, Object> tgtPropMap = MapUtil.pojoToMap(ele);
				Map<String, Object> actPropMap = MapUtil.pojoToMap(actProp);
				AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
			});
		}

		// SellOutActivity
		if (tgtProductInCartBean.getSellOutActivity() != null) {
			if (actProductInCartBean.getSellOutActivity() != null) {
				Map<String, Object> tgtPropMap = MapUtil.pojoToMap(tgtProductInCartBean.getSellOutActivity());
				Map<String, Object> actPropMap = MapUtil.pojoToMap(actProductInCartBean.getSellOutActivity());
				AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
			} else {
				Logger.verifyNotNull(actProductInCartBean.getSellOutActivity(), desc);
			}
		}

	}

	// 商品明细 GetProductDetailListByProductIdList
	// =================================================================================================================================
	@SuppressWarnings({ "deprecation", "rawtypes", "unchecked" })
	public static ProductInDetailBean getProductInDetailBean(String productId, int prodInActivityId, int nextProdInActId, int liveId) throws Exception {
		ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();

		ProductsWapper productsWapper = new ProductsWapper();
		Map<String, Object> productMap = productsWapper.getByProductId(productId);
		Logger.debug("productMap:"+productMap);
		// 组装数据
		// - 商品信息
		ProductInDetailBean productInDetailBean = new ProductInDetailBean();
		productInDetailBean.setProdId(Integer.parseInt(productMap.get("ipid").toString()));
		productInDetailBean.setProductId(productId);
		productInDetailBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));
		productInDetailBean.setTitle(productMap.get("title").toString());
		productInDetailBean.setIntroduction(productMap.get("intro") == null ? "" : productMap.get("intro").toString());
		productInDetailBean.setValidStart((Date) productMap.get("start"));
		productInDetailBean.setValidEnd((Date) productMap.get("end"));
		productInDetailBean.setSellerId(Integer.parseInt(productMap.get("sid").toString()));
		productInDetailBean.setSellerName(productMap.get("sname").toString());
		productInDetailBean.setBrandId(Integer.parseInt(productMap.get("bid").toString()));
		productInDetailBean.setBrandName(productMap.get("brand").toString());
		productInDetailBean.setBrandEnName(productMap.get("ebrand").toString());
		productInDetailBean.setMasterCategoryId(Integer.parseInt(productMap.get("mcatid").toString()));
		productInDetailBean.setMasterCategoryName(productMap.get("mcatname").toString());
		productInDetailBean.setCategoryId(Integer.parseInt(productMap.get("scatid").toString()));
		productInDetailBean.setPackageDeliveryType(Integer.parseInt(productMap.get("pdt").toString()));

		productInDetailBean.setCategoryName(productMap.get("scatname").toString());
		productInDetailBean.setThirdCategoryId(Integer.parseInt(productMap.get("tcatid").toString()));
		productInDetailBean.setThirdCategoryName(productMap.get("tcatname").toString());
		productInDetailBean.setCatalogType(Integer.parseInt(productMap.get("ctype").toString()));
		productInDetailBean.setDeliveryMethod(Integer.parseInt(productMap.get("deliv").toString()));
		productInDetailBean.setBondedArea(Integer.parseInt(productMap.get("bonded").toString()));
		productInDetailBean.setTariffType(Integer.parseInt(productMap.get("tariffy").toString()));
		productInDetailBean.setIsFreeShipping(Double.parseDouble(productMap.get("shipping").toString()) <= 0);
		productInDetailBean.setCountryId(Integer.parseInt(productMap.get("country").toString()));
		productInDetailBean.setAddTime((Date) productMap.get("addtime"));
		productInDetailBean.setLocalReturn(Integer.parseInt(productMap.get("localr").toString()));
		productInDetailBean.setNoticeRisk(Boolean.parseBoolean(productMap.get("risk").toString()));
		productInDetailBean.setProductCode(productMap.get("pcode") == null ? "" : productMap.get("pcode").toString());
		productInDetailBean.setNoReasonReturn(Boolean.parseBoolean(productMap.get("noreason").toString()));
		productInDetailBean
				.setIsNewProduct(getNewestProduct(Boolean.parseBoolean(productMap.get("isnew").toString()), (Date) productMap.get("newstart"), (Date) productMap.get("newend")));

		productInDetailBean.setNewStartTime((Date) productMap.get("newstart"));
		productInDetailBean.setNewEndTime((Date) productMap.get("newend"));
		productInDetailBean.setIsHotRecmd(Boolean.parseBoolean(productMap.get("istop").toString()));
		productInDetailBean.setIsPspProduct(Boolean.parseBoolean(productMap.get("ispsp").toString()));
		productInDetailBean.setGrade(productMap.get("grade").toString());
		productInDetailBean.setHasTextDescription(Boolean.parseBoolean(productMap.get("newdesc").toString()));
		productInDetailBean.setGrouponVersion(Integer.parseInt(productMap.get("goversion").toString()));
		productInDetailBean.setSizePicList(new ArrayList<>());
		//商品类型(0- C2C商品，1- 全球优选商品 3-微信代购商品)
		productInDetailBean.setProductType(Integer.parseInt(productMap.get("ptype").toString()));
		//礼包类型(0- 非礼包，1- 礼包商品)
		if (Integer.parseInt(productMap.get("gtype").toString())==1){
			productInDetailBean.setGiftType(1);
		}else{
			productInDetailBean.setGiftType(0);
		}

		productInDetailBean.setGlobalProductType(Integer.parseInt(productMap.get("gtype").toString()));
		// video
		if (productMap.containsKey("v") && productMap.get("v") != null) {
			JSONObject jsonObject = new JSONObject(productMap.get("v").toString());

			ProductVideoBean productVideoBean = new ProductVideoBean();

			productVideoBean.setVideoUrl(jsonObject.getString("u"));
			productVideoBean.setVideoLength(jsonObject.getInt("l"));
			productVideoBean.setVideoWidth(jsonObject.getInt("w"));
			productVideoBean.setVideoHeight(jsonObject.getInt("h"));
			productVideoBean.setVideoSize(jsonObject.getInt("s"));

			productInDetailBean.setVideo(productVideoBean);

		}

		// pic list
		List<String> picList = new ArrayList<>();
		if (productMap.get("pics") != null) {
			JSONArray jsonArray = new JSONArray(productMap.get("pics").toString());
			for (int i = 0; i < jsonArray.length(); i++) {
				picList.add(jsonArray.getString(i));
			}
		}
		productInDetailBean.setPicList(picList);

		productInDetailBean.setStatus(getProductStatus(productId, prodInActivityId, liveId));

		productInDetailBean.setWeight(0d);
		// 不用检查，前端已不使用
		productInDetailBean.setLimitNum(0);
		productInDetailBean.setLimitNumStartTime(new Date(1900, 1, 1));

		// To do
		// OwnProduct, ExtraDeliveryFee, ExtraDeliveryType
		productInDetailBean.setOwnProduct(Integer.parseInt(productMap.get("own").toString()) == 1 ? true : false);
		productInDetailBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));
		productInDetailBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));

//		productInDetailBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));

		// 规格信息
		// 如规格参加了活动，填充活动相关信息
		List<CatalogInActivityInDetailBean> catalogInActivityInDetailBeans = new ArrayList<>();
		if (prodInActivityId > 0) {
			Map<String, Object> maps = activityProductsWapper.getByProdInActivityId(prodInActivityId);
			JSONArray catalogsAry = new JSONArray(maps.get("catalogs").toString());
			for (int j = 0; j < catalogsAry.length(); j++) {
				JSONObject catalogInfo = catalogsAry.getJSONObject(j);
				CatalogInActivityInDetailBean catalogInActivityInDetailBean = new CatalogInActivityInDetailBean();
				catalogInActivityInDetailBean.setCatalogId(catalogInfo.getString("cid"));
				catalogInActivityInDetailBean.setActivityPrice(catalogInfo.getDouble("price"));
				catalogInActivityInDetailBean.setActivityStock(catalogInfo.getInt("stock"));
				catalogInActivityInDetailBeans.add(catalogInActivityInDetailBean);
			}
		}

		// 如规格参加了下一场活动，填充活动相关信息
		List<CatalogInActivityInDetailBean> next_catalogInActivityInDetailBeans = new ArrayList<>();
		if (nextProdInActId > 0) {
			Map<String, Object> maps = activityProductsWapper.getByProdInActivityId(nextProdInActId);
			if(Integer.parseInt(maps.get("atype").toString())!=2){
				JSONArray catalogsAry = new JSONArray(maps.get("catalogs").toString());
				for (int j = 0; j < catalogsAry.length(); j++) {
					JSONObject catalogInfo = catalogsAry.getJSONObject(j);
					CatalogInActivityInDetailBean catalogInActivityInDetailBean = new CatalogInActivityInDetailBean();
					catalogInActivityInDetailBean.setCatalogId(catalogInfo.getString("cid"));
					catalogInActivityInDetailBean.setActivityPrice(catalogInfo.getDouble("price"));
					catalogInActivityInDetailBean.setActivityStock(catalogInfo.getInt("stock"));
					next_catalogInActivityInDetailBeans.add(catalogInActivityInDetailBean);
				}
			}
		}

		// 填充规格信息
		List<CatalogInDetailBean> CatalogInDetailBeanList = new ArrayList<>();
		CatalogsWapper catalogsWapper = new CatalogsWapper();
		List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());

		List<Map<String, Object>> catalogMapList = new ArrayList<>();
		catalogs.forEach(ele -> {
			try {
				catalogMapList.add(catalogsWapper.getByCatalogId(ele));
			} catch (Exception e) {
				e.printStackTrace();
			}
		});

//		List<GroupCatalogs> CatalogPriceList = null;
//		if(Integer.parseInt(productMap.get("goversion").toString())>0){
//			String groupCatalogs = catalogsWapper.getGroupProductByProductId(productId).get(0).get("catalogs").toString();
//			String groupCatalogs = catalogsWapper.getByCatalogId(productId);
//			CatalogPriceList=(List<GroupCatalogs>) FormatUtil.GSONToObject(groupCatalogs, new TypeToken<List<GroupCatalogs>>(){}.getType());
//		}

		Logger.debug("catalogMapList:"+catalogMapList);
		for (int i = 0; i < catalogMapList.size(); i++) {
			Map<String, Object> catalogMap = catalogMapList.get(i);
			String catalogId = catalogMap.get("cid").toString();

			CatalogInDetailBean catalogInDetailBean = new CatalogInDetailBean();
			catalogInDetailBean.setCatalogId(catalogId);
			catalogInDetailBean.setSKU(String.valueOf(catalogMap.get("sku") == null ? "" : catalogMap.get("sku").toString()));
			catalogInDetailBean.setIsPreSale(Boolean.parseBoolean(catalogMap.get("presale").toString()));
			catalogInDetailBean.setPrice(Double.parseDouble(catalogMap.get("price").toString()));
			catalogInDetailBean.setNewGuestPrice(Double.parseDouble(catalogMap.get("newp").toString()));
			catalogInDetailBean.setVipPrice(Double.parseDouble(catalogMap.get("vip").toString()));
			catalogInDetailBean.setCatalogStock(Integer.parseInt(catalogMap.get("stock").toString()));
			catalogInDetailBean.setCommission(Double.parseDouble(catalogMap.get("commission").toString()));

			if (catalogMap.get("commissions")!=null){
				String[] saleCommissions = catalogMap.get("commissions").toString().split(",");
				catalogInDetailBean.setCommissionList(Arrays.asList(new BigDecimal(saleCommissions[0]).setScale(0).doubleValue(),new BigDecimal(saleCommissions[1]).setScale(0).doubleValue(),new BigDecimal(saleCommissions[2]).setScale(0).doubleValue()));
			}else{
				catalogInDetailBean.setCommissionList(null);
			}

			catalogInDetailBean.setMarketPrice(Double.parseDouble(catalogMap.get("mprice").toString()));
			catalogInDetailBean.setWeight(Double.parseDouble(catalogMap.get("wt").toString()));
			Map<String,Object> map = catalogsWapper.getByCatalogId(catalogId);
			if(map.get("goprice")!=null){
				catalogInDetailBean.setGrouponPrice(Double.parseDouble(map.get("goprice").toString()));
			}else{
				catalogInDetailBean.setGrouponPrice(0.0);
			}

//			if(CatalogPriceList!=null&&catalogId.equals(CatalogPriceList.get(i).getCid())){
//				catalogInDetailBean.setGrouponPrice(CatalogPriceList.get(i).getPrice());
//			}else{
//				catalogInDetailBean.setGrouponPrice(0.0);
//			}
			// to do
			// 多 ,IsExtraDelivery,

			// 属性值 todo sort
			List<CatalogPropsInDetailBean> properties = new ArrayList<>();
			if (catalogMap.get("props") == null) {
				// 添加一个空的
				CatalogPropsInDetailBean catalogPropsInDetailBean = new CatalogPropsInDetailBean();
				properties.add(catalogPropsInDetailBean);
			} else {
				JSONArray propsAry = new JSONArray(catalogMap.get("props").toString());
				for (int j = 0; j < propsAry.length(); j++) {
					JSONObject prop = propsAry.getJSONObject(j);
					CatalogPropsInDetailBean catalogPropsInDetailBean = new CatalogPropsInDetailBean();
					catalogPropsInDetailBean.setName(prop.getString("name"));
					catalogPropsInDetailBean.setValue(prop.getString("value"));
					catalogPropsInDetailBean.setPicUrl(prop.getString("pic"));
					properties.add(catalogPropsInDetailBean);
				}
			}

			catalogInDetailBean.setActivityPrice(0d);
			catalogInDetailBean.setActivityStock(0);
			catalogInDetailBean.setIsInActivity(false);
			// 规格存在活动中
			if (catalogInActivityInDetailBeans.size() > 0) {
				CatalogInActivityInDetailBean catalogInActivityInDetailBean = catalogInActivityInDetailBeans.stream().filter(x -> x.getCatalogId().equals(catalogId)).findFirst()
						.orElse(null);
				if (catalogInActivityInDetailBean != null) {
					catalogInDetailBean.setActivityPrice(catalogInActivityInDetailBean.getActivityPrice());
					catalogInDetailBean.setActivityStock(catalogInActivityInDetailBean.getActivityStock());
					catalogInDetailBean.setIsInActivity(true);
				}
			}

			// 规格在下场活动中
			catalogInDetailBean.setNextActivityPrice(0d);
			catalogInDetailBean.setNextActivityStock(0);
			if (next_catalogInActivityInDetailBeans.size() > 0) {
				CatalogInActivityInDetailBean catalogInActivityInDetailBean = next_catalogInActivityInDetailBeans.stream().filter(x -> x.getCatalogId().equals(catalogId))
						.findFirst().orElse(null);
				if (catalogInActivityInDetailBean != null) {
					catalogInDetailBean.setNextActivityPrice(catalogInActivityInDetailBean.getActivityPrice());
					catalogInDetailBean.setNextActivityStock(catalogInActivityInDetailBean.getActivityStock());
				}
			}

			catalogInDetailBean.setPropertyList(properties);
			CatalogInDetailBeanList.add(catalogInDetailBean);
		}
		productInDetailBean.setCatalogList(CatalogInDetailBeanList);

		// new property
		// IsCurActivitySellOut 只有有当前活动，并且所以规格活动库存为0 就为true，否则为true
		int sumActivityStock = productInDetailBean.getCatalogList().stream().collect(Collectors.summingInt(CatalogInDetailBean::getActivityStock));
		if (prodInActivityId < -1 && sumActivityStock == 0) {
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(Math.abs(prodInActivityId));
			Logger.debug("activityProductMap:" + activityProductMap);
			SellOutActivityBean sellOutActivityBean = new SellOutActivityBean();
			sellOutActivityBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
			sellOutActivityBean.setActivityName(activityProductMap.get("aname").toString());
			sellOutActivityBean.setMarketPrice(Double.valueOf(activityProductMap.get("market").toString()));

			int allActivityStock = 0;
			List<Double> priceList = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				allActivityStock = allActivityStock + catalogsAry.getJSONObject(i).getInt("stock");
				Double price = catalogsAry.getJSONObject(i).getDouble("price");
				priceList.add(price);
			}

			Collections.sort(priceList);
			Logger.debug("priceList:" + priceList);
			if (allActivityStock == 0) {
				sellOutActivityBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
				sellOutActivityBean.setActivityName(activityProductMap.get("aname").toString());
				sellOutActivityBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
				sellOutActivityBean.setActivityLevel(Integer.parseInt(activityProductMap.get("alevel").toString()));
				sellOutActivityBean.setMinPrice(priceList.get(0));
				sellOutActivityBean.setMaxPrice(priceList.get(priceList.size()-1));
			}
			productInDetailBean.setSellOutActivity(sellOutActivityBean);
		}

		// 活动信息
		if (prodInActivityId > 0) {
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(prodInActivityId);
			Logger.debug(activityProductMap);
			ProductActivityInDetailBean productActivityInDetailBean = new ProductActivityInDetailBean();
			productActivityInDetailBean.setProductId(productId);
			productActivityInDetailBean.setProductInActivityId(prodInActivityId);
			productActivityInDetailBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
			productActivityInDetailBean.setActivityName(String.valueOf(activityProductMap.get("aname")));
			productActivityInDetailBean.setActivityStartTime((Date) activityProductMap.get("start"));
			productActivityInDetailBean.setActivityEndTime((Date) activityProductMap.get("end"));
			productActivityInDetailBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
			productActivityInDetailBean.setActivityLimit(Integer.parseInt(activityProductMap.get("alimit").toString()));
			productActivityInDetailBean.setActivityProductLimit(Integer.parseInt(activityProductMap.get("plimit").toString()));
			productActivityInDetailBean.setIsNewBuyer(Boolean.parseBoolean(activityProductMap.get("nbuyer").toString()));
			productActivityInDetailBean.setIsPartCatalogs(Boolean.parseBoolean(activityProductMap.get("part").toString()));
			productActivityInDetailBean.setIsTradeIsolation(Boolean.parseBoolean(activityProductMap.get("isolation").toString()));

			productActivityInDetailBean.setBeginTimeOfProductInActivity((Date) activityProductMap.get("start"));
			productActivityInDetailBean.setEndTimeOfProductInActivity((Date) activityProductMap.get("end"));
			productActivityInDetailBean.setActivityLevel(Integer.parseInt(activityProductMap.get("alevel").toString()));
			productActivityInDetailBean.setEarnest(Double.parseDouble(activityProductMap.get("earnest").toString()));
			productActivityInDetailBean.setEarnestDedution(Double.parseDouble(activityProductMap.get("ededution").toString()));
			productActivityInDetailBean.setActivityType(Integer.parseInt(activityProductMap.get("atype").toString()));

			if (activityProductMap.keySet().contains("member")) {
				productActivityInDetailBean.setIsMember(Boolean.parseBoolean(activityProductMap.get("member").toString()));
			} else {
				productActivityInDetailBean.setIsMember(false);
			}

			// 弃用
			productActivityInDetailBean.setPromotionType(3);
			productActivityInDetailBean.setPromotion(0);

			List<String> catalogList = new ArrayList<>();
			List<Double> priceList = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				catalogList.add(catalogsAry.getJSONObject(i).getString("cid"));
				priceList.add(catalogsAry.getJSONObject(i).getDouble("price"));
			}

			productActivityInDetailBean.setMaxActivityPrice(priceList.stream().max((x, y) -> Double.compare(x, y)).get());
			productActivityInDetailBean.setMinActivityPrice(priceList.stream().min((x, y) -> Double.compare(x, y)).get());
			productActivityInDetailBean.setCatalogList(catalogList);

			// 设置商品的有效期, 直播有效取直播时间， 直播无效活动有效，取活动时间
			productInDetailBean.setValidStart((Date) activityProductMap.get("start"));
			productInDetailBean.setValidEnd((Date) activityProductMap.get("end"));

			// 填值
			productInDetailBean.setProductActivity(productActivityInDetailBean);

		}

		// 下一次活动
		if (nextProdInActId > 0) {
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(nextProdInActId);
			ProductActivityInDetailBean productActivityInDetailBean = new ProductActivityInDetailBean();
			productActivityInDetailBean.setProductId(productId);
			productActivityInDetailBean.setProductInActivityId(nextProdInActId);
			productActivityInDetailBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
			productActivityInDetailBean.setActivityName(String.valueOf(activityProductMap.get("aname")));
			productActivityInDetailBean.setActivityStartTime((Date) activityProductMap.get("start"));
			productActivityInDetailBean.setActivityEndTime((Date) activityProductMap.get("end"));
			productActivityInDetailBean.setMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
			productActivityInDetailBean.setActivityLimit(Integer.parseInt(activityProductMap.get("alimit").toString()));
			productActivityInDetailBean.setActivityProductLimit(Integer.parseInt(activityProductMap.get("plimit").toString()));
			productActivityInDetailBean.setIsNewBuyer(Boolean.parseBoolean(activityProductMap.get("nbuyer").toString()));
			productActivityInDetailBean.setIsPartCatalogs(Boolean.parseBoolean(activityProductMap.get("part").toString()));
			productActivityInDetailBean.setIsTradeIsolation(Boolean.parseBoolean(activityProductMap.get("isolation").toString()));

			productActivityInDetailBean.setBeginTimeOfProductInActivity((Date) activityProductMap.get("start"));
			productActivityInDetailBean.setEndTimeOfProductInActivity((Date) activityProductMap.get("end"));
			productActivityInDetailBean.setActivityLevel(Integer.parseInt(activityProductMap.get("alevel").toString()));

			if (activityProductMap.keySet().contains("member")) {
				productActivityInDetailBean.setIsMember(Boolean.parseBoolean(activityProductMap.get("member").toString()));
			} else {
				productActivityInDetailBean.setIsMember(false);
			}

			// 弃用
			productActivityInDetailBean.setPromotionType(3);
			productActivityInDetailBean.setPromotion(0);

			List<String> catalogList = new ArrayList<>();
			List<Double> priceList = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				catalogList.add(catalogsAry.getJSONObject(i).getString("cid"));
				priceList.add(catalogsAry.getJSONObject(i).getDouble("price"));
			}

			productActivityInDetailBean.setMaxActivityPrice(priceList.stream().max((x, y) -> Double.compare(x, y)).get());
			productActivityInDetailBean.setMinActivityPrice(priceList.stream().min((x, y) -> Double.compare(x, y)).get());
			productActivityInDetailBean.setCatalogList(catalogList);

			// 填值
			productInDetailBean.setNextActivity(productActivityInDetailBean);

		}

		// 直播
		if (liveId > 0) {
			LiveProductsWapper liveProductsWapper = new LiveProductsWapper();
			Map<String, Object> liveProdMap = liveProductsWapper.getByActivityId(liveId);

			LiveProductInDetailBean liveProduct = new LiveProductInDetailBean();
			liveProduct.setProductId(productId);
			liveProduct.setLiveId(liveId);
			// liveProduct.setLiveName(liveProdMap.get("name").toString());
			liveProduct.setSellerId(Integer.parseInt(liveProdMap.get("sid").toString()));
			liveProduct.setCommentCount(Integer.parseInt(liveProdMap.get("comments").toString()));
			liveProduct.setStartTime((Date) liveProdMap.get("start"));
			liveProduct.setEndTime((Date) liveProdMap.get("end"));
			liveProduct.setAddTime((Date) liveProdMap.get("add"));
			liveProduct.setBrandName(liveProdMap.get("brand").toString());
			liveProduct.setBrandEnName(liveProdMap.get("ebrand").toString());
			liveProduct.setBrandId(Integer.parseInt(liveProdMap.get("bid").toString()));

			liveProduct.setMasterCategoryId(Integer.parseInt(productMap.get("mcatid").toString()));
			liveProduct.setMasterCategoryName(productMap.get("mcatname").toString());
			liveProduct.setCategoryId(Integer.parseInt(productMap.get("scatid").toString()));
			liveProduct.setCategoryName(productMap.get("scatname").toString());
			liveProduct.setThirdCategoryId(Integer.parseInt(productMap.get("tcatid").toString()));
			liveProduct.setThirdCategoryName(productMap.get("tcatname").toString());

			liveProduct.setSellStatus(Integer.parseInt(liveProdMap.get("status").toString()));
			liveProduct.setIsTop(Boolean.parseBoolean(liveProdMap.get("istop").toString()));
			liveProduct.setReadyPutawayProductSort(Double.parseDouble(liveProdMap.get("sort").toString()));

			// 设置商品的有效期, 直播有效取直播时间， 直播无效活动有效，取活动时间
			productInDetailBean.setValidStart((Date) liveProdMap.get("start"));
			productInDetailBean.setValidEnd((Date) liveProdMap.get("end"));

			// 填值
			productInDetailBean.setLiveProduct(liveProduct);
		}

		return productInDetailBean;

	}

	public static void compareProductInDetailBean(List<String> productList, List<ProductInDetailBean> tgtProductInDetailBeanList,
			List<ProductInDetailBean> actProductInDetailBeanList, String desc) {
		compareListBean(productList, tgtProductInDetailBeanList, actProductInDetailBeanList, desc, (x) -> x.getProductId(), (x, y, z) -> compareProductInDetailBean(x, y, z));

	}

	public static void compareProductInDetailBean(ProductInDetailBean tgtProductInDetailBean, ProductInDetailBean actProductInDetailBean, String desc) {
		// 第一层数据对比
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtProductInDetailBean);
		tgtMap.remove("ProductActivity");
		tgtMap.remove("NextActivity");
		tgtMap.remove("LiveProduct");
		tgtMap.remove("CatalogList");
		tgtMap.remove("SellOutActivity");
		tgtMap.remove("Video");
		tgtMap.remove("DeliveryTemplateList");
		tgtMap.remove("CurrencyExchangeRate");

		Map<String, Object> actMap = MapUtil.pojoToMap(actProductInDetailBean);
		actMap.remove("ProductActivity");
		actMap.remove("NextActivity");
		actMap.remove("LiveProduct");
		actMap.remove("CatalogList");
		actMap.remove("SellOutActivity");
		actMap.remove("Video");
		actMap.remove("DeliveryTemplateList");
		actMap.remove("CurrencyExchangeRate");

		// ignore
		removeIgnoreKey(tgtMap);
		removeIgnoreKey(actMap);

		AssertService.assertResultEqual(tgtMap, actMap, desc);

		// 第二层数据比对
		CurrencyExchangeRateDto tgtcurrencyExchangeRate = tgtProductInDetailBean.getCurrencyExchangeRate();
		CurrencyExchangeRateDto actcurrencyExchangeRate = actProductInDetailBean.getCurrencyExchangeRate();

		if (tgtcurrencyExchangeRate!=null){
			Logger.verifyEquals(tgtcurrencyExchangeRate.getCurrency(),actcurrencyExchangeRate.getCurrency(),"验证Currency");
		}

		//模板
		List<DeliveryTemplateDto> tgtDeliveryTemplateList = tgtProductInDetailBean.getDeliveryTemplateList();
		List<DeliveryTemplateDto> actDeliveryTemplateList = actProductInDetailBean.getDeliveryTemplateList();
		if (tgtDeliveryTemplateList!=null){
			Logger.verifyEquals(tgtDeliveryTemplateList.size(),actDeliveryTemplateList.size(),"验证模板数量应该一致");
			tgtDeliveryTemplateList.forEach(tgt->{
				DeliveryTemplateDto deliveryTemplateDto = actDeliveryTemplateList.stream().filter(act -> act.getTemplateId() == tgt.getTemplateId()).findFirst().orElse(null);
				if (deliveryTemplateDto!=null){
					Map<String, Object> tgtCatalogMap = MapUtil.pojoToMap(tgt);
					Map<String, Object> actCatalogMap = MapUtil.pojoToMap(deliveryTemplateDto);
					AssertService.assertResultEqual(tgtCatalogMap, actCatalogMap, desc);
				}
			});
		}


		// 规格
		List<CatalogInDetailBean> tgtCatalogInDetailBeanList = tgtProductInDetailBean.getCatalogList();
		List<CatalogInDetailBean> actCatalogInDetailBeanList = actProductInDetailBean.getCatalogList();
		Logger.verifyEquals(tgtCatalogInDetailBeanList.size(), actCatalogInDetailBeanList.size(), desc + ",规格数量应该相等");

		tgtCatalogInDetailBeanList.forEach(tgt -> {
			CatalogInDetailBean actCatalogInDetailBean = actCatalogInDetailBeanList.stream().filter(act -> act.getCatalogId().equals(tgt.getCatalogId())).findFirst().orElse(null);
			if (actCatalogInDetailBean != null) {
				Map<String, Object> tgtCatalogMap = MapUtil.pojoToMap(tgt);
				tgtCatalogMap.remove("PropertyList");
				Map<String, Object> actCatalogMap = MapUtil.pojoToMap(actCatalogInDetailBean);
				actCatalogMap.remove("actCatalogMap");

				AssertService.assertResultEqual(tgtCatalogMap, actCatalogMap, desc);

				// 属性 值比较
				List<CatalogPropsInDetailBean> tgtProps = tgt.getPropertyList();
				List<CatalogPropsInDetailBean> actProps = actCatalogInDetailBean.getPropertyList();

				Logger.verifyEquals(tgtProps.size(), actProps.size(), desc + ", catalogId:" + tgt.getCatalogId() + " 属性值个数不匹配");

				if (tgtProps.size() == 1 && tgtProps.get(0).getName() == null) {
					// 单规格
					Logger.verifyEquals(1, actProps.size(), "单规格，属性节点个数为1");
					Logger.verifyIsNull(actProps.get(0).getName(), "单规格属性为null");
					Logger.verifyIsNull(actProps.get(0).getPicUrl(), "单规格属性为null");
					Logger.verifyIsNull(actProps.get(0).getValue(), "单规格属性为null");

				} else {
					tgtProps.forEach(ele -> {
						CatalogPropsInDetailBean actProp = actProps.stream().filter(y -> y.getName().equals(ele.getName())).findFirst().orElse(null);
						Map<String, Object> tgtPropMap = MapUtil.pojoToMap(ele);
						Map<String, Object> actPropMap = MapUtil.pojoToMap(actProp);
						AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
					});
				}
			} else {
				Logger.verifyEquals(false, true, desc + ", catalogId: " + tgt.getCatalogId() + "中不存在");
			}

		});

		// 直播
		if (tgtProductInDetailBean.getLiveProduct() != null) {
			Map<String, Object> tgtLiveMap = MapUtil.pojoToMap(tgtProductInDetailBean.getLiveProduct());
			Map<String, Object> actLiveMap = MapUtil.pojoToMap(actProductInDetailBean.getLiveProduct());

			removeLiveProdIgnoreKey(tgtLiveMap);
			removeLiveProdIgnoreKey(actLiveMap);

			AssertService.assertResultEqual(tgtLiveMap, actLiveMap, desc);
		} else {
			Logger.verifyIsNull(actProductInDetailBean.getLiveProduct(), desc);
		}

		// 当前活动
		if (tgtProductInDetailBean.getProductActivity() != null) {
			Map<String, Object> tgtActivityMap = MapUtil.pojoToMap(tgtProductInDetailBean.getProductActivity());
			tgtActivityMap.remove("CatalogList");
			Map<String, Object> actActivityMap = MapUtil.pojoToMap(actProductInDetailBean.getProductActivity());
			actActivityMap.remove("CatalogList");

			removeActivityIgnoreKey(tgtActivityMap);
			removeActivityIgnoreKey(actActivityMap);

			AssertService.assertResultEqual(tgtActivityMap, actActivityMap, desc);

			AssertService.checkArray(tgtProductInDetailBean.getProductActivity().getCatalogList(), actProductInDetailBean.getProductActivity().getCatalogList());
		} else {
			Logger.verifyIsNull(actProductInDetailBean.getProductActivity(), desc);
		}

		// 下一场活动
		if (tgtProductInDetailBean.getNextActivity() != null) {
			Map<String, Object> tgtActivityMap = MapUtil.pojoToMap(tgtProductInDetailBean.getNextActivity());
			tgtActivityMap.remove("CatalogList");
			Map<String, Object> actActivityMap = MapUtil.pojoToMap(actProductInDetailBean.getNextActivity());
			actActivityMap.remove("CatalogList");

			removeActivityIgnoreKey(tgtActivityMap);
			removeActivityIgnoreKey(actActivityMap);

			AssertService.assertResultEqual(tgtActivityMap, actActivityMap, desc);

			AssertService.checkArray(tgtProductInDetailBean.getNextActivity().getCatalogList(), actProductInDetailBean.getNextActivity().getCatalogList());
		} else {
			Logger.verifyIsNull(actProductInDetailBean.getNextActivity(), desc);
		}

		// SellOutActivity
		if (tgtProductInDetailBean.getSellOutActivity() != null) {
			if (actProductInDetailBean.getSellOutActivity() != null) {
				Map<String, Object> tgtPropMap = MapUtil.pojoToMap(tgtProductInDetailBean.getSellOutActivity());
				Map<String, Object> actPropMap = MapUtil.pojoToMap(actProductInDetailBean.getSellOutActivity());
				AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
			} else {
				Logger.verifyNotNull(actProductInDetailBean.getSellOutActivity(), desc);
			}
		}

		if (tgtProductInDetailBean.getVideo() != null) {
			if (actProductInDetailBean.getVideo() != null) {
				Map<String, Object> tgtPropMap = MapUtil.pojoToMap(tgtProductInDetailBean.getVideo());
				Map<String, Object> actPropMap = MapUtil.pojoToMap(actProductInDetailBean.getVideo());
				AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
			} else {
				Logger.verifyNotNull(actProductInDetailBean.getVideo(), desc);
			}
		}

	}

	// 商品简表 GetProductListByProductIdList
	// =================================================================================================================================
	public static ProductInListBean getProductInListBean(String productId, int prodInActivityId, int liveId) throws Exception {
		ProductsWapper productsWapper = new ProductsWapper();
		CatalogsWapper catalogsWapper = new CatalogsWapper();

		Map<String, Object> productMap = productsWapper.getByProductId(productId);
		@SuppressWarnings("rawtypes")
		List<Map> catalogMap = catalogsWapper.getAllByProductId(productId);

		ProductInListBean productInListBean = new ProductInListBean();
		productInListBean.setProdId(Integer.parseInt(productMap.get("ipid").toString()));
		productInListBean.setProductId(productId);
		productInListBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));
		productInListBean.setTitle(productMap.get("title").toString());
		productInListBean.setMaxPrice(Double.parseDouble(productMap.get("maxp").toString().split(",")[0]));
		productInListBean.setMinPrice(Double.parseDouble(productMap.get("minp").toString().split(",")[0]));
		productInListBean.setValidStart((Date) productMap.get("start"));
		productInListBean.setValidEnd((Date) productMap.get("end"));
		productInListBean.setSellerId(Integer.parseInt(productMap.get("sid").toString()));
		productInListBean.setSellerName(productMap.get("sname").toString());
		productInListBean.setCountryId(Integer.parseInt(productMap.get("country").toString()));
		productInListBean.setTariffType(Integer.parseInt(productMap.get("tariffy").toString()));
		productInListBean.setIsFreeShipping(Double.parseDouble(productMap.get("shipping").toString()) <= 0);
		productInListBean.setDeliveryMethod(Integer.parseInt(productMap.get("deliv").toString()));
		productInListBean
				.setIsNewProduct(getNewestProduct(Boolean.parseBoolean(productMap.get("isnew").toString()), (Date) productMap.get("newstart"), (Date) productMap.get("newend")));

		productInListBean.setNewStartTime((Date) productMap.get("newstart"));
		productInListBean.setNewEndTime((Date) productMap.get("newend"));
		productInListBean.setIsHotRecmd(Boolean.parseBoolean(productMap.get("istop").toString()));
		productInListBean.setIsPspProduct(Boolean.parseBoolean(productMap.get("ispsp").toString()));

		List<Integer> stocks = new ArrayList<>();
		List<Boolean> isPreList = new ArrayList<>();
		catalogMap.forEach(ele -> {
			isPreList.add(Boolean.parseBoolean(ele.get("presale").toString()));
			stocks.add(Integer.parseInt(ele.get("stock").toString()));
		});

		productInListBean.setIsAnyPreSale(isPreList.stream().anyMatch(c -> c));
		productInListBean.setIsAllPreSale(isPreList.stream().allMatch(c -> c));
		productInListBean.setStock(stocks.stream().collect(Collectors.summingInt(Integer::intValue)));

		productInListBean.setOwnProduct(Integer.parseInt(productMap.get("own").toString()) == 1 ? true : false);

		// main pic
		productInListBean.setMainPic(new JSONArray(productMap.get("pics").toString()).getString(0));

		// 先填0，后面判断
		productInListBean.setLiveId(0);
		productInListBean.setActivityId(0);
		productInListBean.setActivityMarketPrice(0d);

		// 有活动
		if (prodInActivityId > 0) {
			ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
			Map<String, Object> activityProductMap = activityProductsWapper.getByProdInActivityId(prodInActivityId);

			List<String> catalogList = new ArrayList<>();
			List<Double> priceList = new ArrayList<>();
			List<Integer> actStock = new ArrayList<>();
			JSONArray catalogsAry = new JSONArray(activityProductMap.get("catalogs").toString());
			for (int i = 0; i < catalogsAry.length(); i++) {
				catalogList.add(catalogsAry.getJSONObject(i).getString("cid"));
				priceList.add(catalogsAry.getJSONObject(i).getDouble("price"));
				actStock.add(catalogsAry.getJSONObject(i).getInt("stock"));
			}

			productInListBean.setActivityId(Integer.parseInt(activityProductMap.get("aid").toString()));
			productInListBean.setMaxPrice(priceList.stream().max((x, y) -> Double.compare(x, y)).get());
			productInListBean.setMinPrice(priceList.stream().min((x, y) -> Double.compare(x, y)).get());
			productInListBean.setStock(actStock.stream().collect(Collectors.summingInt(Integer::intValue)));
			productInListBean.setActivityMarketPrice(Double.parseDouble(activityProductMap.get("market").toString()));
			productInListBean.setValidStart((Date) activityProductMap.get("start"));
			productInListBean.setValidEnd((Date) activityProductMap.get("end"));

		}

		// 有直播
		if (liveId > 0) {
			LiveProductsWapper liveProductsWapper = new LiveProductsWapper();
			Map<String, Object> liveProdMap = liveProductsWapper.getByActivityId(liveId);
			productInListBean.setLiveId(liveId);
			productInListBean.setValidStart((Date) liveProdMap.get("start"));
			productInListBean.setValidEnd((Date) liveProdMap.get("end"));

		}

		// status
		productInListBean.setStatus(getProductStatus(productId, prodInActivityId, liveId));

		return productInListBean;

	}

	public static void compareProductInListBean(List<String> productList, List<ProductInListBean> tgtProductInListBeanList, List<ProductInListBean> actProductInListBeanList,
			String desc) {
		compareListBean(productList, tgtProductInListBeanList, actProductInListBeanList, desc, (x) -> x.getProductId(), (x, y, z) -> compareProductInListBean(x, y, z));
	}

	public static void compareProductInListBean(ProductInListBean tgtProductInListBean, ProductInListBean actProductInListBean, String desc) {
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtProductInListBean);
		Map<String, Object> actMap = MapUtil.pojoToMap(actProductInListBean);
		AssertService.assertResultEqual(tgtMap, actMap, desc);
	}

	// 直播置顶 GetTopProductListByLiveId
	// =================================================================================================================================
	public static List<TopProductInLiveBean> geTopProductInLiveBean(int liveId) throws Exception {
		LiveProductsWapper liveProductsWapper = new LiveProductsWapper();
		List<String> prodList = liveProductsWapper.getListByActivityId(liveId).stream().map(ele -> ele.get("spid").toString()).collect(Collectors.toList());

		List<ProductInListBean> productInListBeanList = new ArrayList<>();
		prodList.forEach(prod -> {

			try {
				productInListBeanList.add(getProductInListBean(prod, 0, liveId));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		});

		List<TopProductInLiveBean> topProductInLiveBeanList = new ArrayList<>();
		productInListBeanList.forEach(ele -> {
			TopProductInLiveBean topProductInLiveBean = new TopProductInLiveBean();
			topProductInLiveBean.setLiveId(liveId);
			topProductInLiveBean.setProductId(ele.getProductId());
			topProductInLiveBean.setPrice(ele.getMinPrice());
			topProductInLiveBean.setIsPspProduct(ele.isIsPspProduct());
			topProductInLiveBean.setPicUrl(ele.getMainPic());
			topProductInLiveBeanList.add(topProductInLiveBean);

		});

		return topProductInLiveBeanList;
	}

	public static void compareTopProductInLiveBean(List<String> prodList, List<TopProductInLiveBean> tgtTopProductInLiveBeanList,
			List<TopProductInLiveBean> actTopProductInLiveBeanList, String desc) {
		compareListBean(prodList, tgtTopProductInLiveBeanList, actTopProductInLiveBeanList, desc, (x) -> x.getProductId(), (x, y, z) -> compareTopProductInLiveBean(x, y, z));
	}

	public static void compareTopProductInLiveBean(TopProductInLiveBean tgtTopProductInLiveBean, TopProductInLiveBean actTopProductInLiveBean, String desc) {
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtTopProductInLiveBean);
		Map<String, Object> actMap = MapUtil.pojoToMap(actTopProductInLiveBean);
		AssertService.assertResultEqual(tgtMap, actMap, desc);
	}

	// 历史库 GetProductListByHistoryProductIdList
	// =================================================================================================================================
	/***
	 *
	 * @param productId
	 * @param isFromHisTbl
	 * @return
	 * @throws Exception
	 */
	public static ProductHistoryBean getProductHistoryBean(String productId, boolean isFromHisTbl) throws Exception {
		ProductHistoryBean productHistoryBean = new ProductHistoryBean();

		if (isFromHisTbl) {
			HistoryProductModelWapper historyProductModelWapper = new HistoryProductModelWapper();

			Map<String, Object> hisMap = historyProductModelWapper.getByProductId(productId);
			Logger.debug("hisMap:" + hisMap);

			productHistoryBean.setProductId(productId);
			productHistoryBean.setTitle(hisMap.get("Title").toString());
			productHistoryBean.setSellerId(Integer.parseInt(hisMap.get("SellerId").toString()));
			productHistoryBean.setSellerName(hisMap.get("SellerName").toString());
			productHistoryBean.setTariffType(Integer.parseInt(hisMap.get("TariffType").toString()));
			Logger.debug("template"+hisMap.get("Templates").toString());
			productHistoryBean.setFreeShipping(hisMap.get("Templates").toString().length()==3?true:false);
			productHistoryBean.setDeliveryMethod(Integer.parseInt(hisMap.get("DeliveryMethod").toString()));
			productHistoryBean.setLocalReturn(Integer.parseInt(hisMap.get("LocalReturn").toString()));
			productHistoryBean.setPrice(Double.parseDouble(hisMap.get("MinCatalogPrice").toString()));
			productHistoryBean.setValidStart((Date) hisMap.get("ValidStart"));
			productHistoryBean.setValidEnd((Date) hisMap.get("ValidEnd"));
			productHistoryBean.setStatus(2);
			productHistoryBean.setMainPic(new JSONArray(hisMap.get("PicList").toString()).getString(0));

		} else {
			ProductsWapper productsWapper = new ProductsWapper();

			Map<String, Object> prodMap = productsWapper.getByProductId(productId);

			productHistoryBean.setProductId(productId);
			productHistoryBean.setTitle(prodMap.get("title").toString());
			productHistoryBean.setSellerId(Integer.parseInt(prodMap.get("sid").toString()));
			productHistoryBean.setSellerName(prodMap.get("sname").toString());
			productHistoryBean.setTariffType(Integer.parseInt(prodMap.get("tariffy").toString()));
			productHistoryBean.setDeliveryMethod(Integer.parseInt(prodMap.get("deliv").toString()));
			productHistoryBean.setLocalReturn(Integer.parseInt(prodMap.get("localr").toString()));
			productHistoryBean.setFreeShipping(Double.parseDouble(prodMap.get("shipping").toString()) <= 0);
			productHistoryBean.setPrice(Double.parseDouble(prodMap.get("minp").toString().split(",")[0]));
			productHistoryBean.setValidStart((Date) prodMap.get("start"));
			productHistoryBean.setValidEnd((Date) prodMap.get("end"));
			productHistoryBean.setStatus(getProductStatus(productId, 0, 0));
			productHistoryBean.setMainPic(new JSONArray(prodMap.get("pics").toString()).getString(0));
		}

		return productHistoryBean;
	}

	public static void compareProductHistoryBean(List<String> prodList, List<ProductHistoryBean> tgtProductHistoryBeanList, List<ProductHistoryBean> actProductHistoryBeanList,
			String desc) {
		compareListBean(prodList, tgtProductHistoryBeanList, actProductHistoryBeanList, desc, (x) -> x.getProductId(), (x, y, z) -> compareProductHistoryBean(x, y, z));
	}

	public static void compareProductHistoryBean(ProductHistoryBean tgtProductHistoryBean, ProductHistoryBean actProductHistoryBean, String desc) {
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtProductHistoryBean);
		Map<String, Object> actMap = MapUtil.pojoToMap(actProductHistoryBean);
		AssertService.assertResultEqual(tgtMap, actMap, desc);
	}

	// 商品图文描述信息 GetProductDescExtraByProductId
	// =================================================================================================================================
	public static ProductDescExtraBean getProductDescExtraBean(String productId) throws Exception {
		ProductDescExtraNewWapper productDescExtraNewWapper = new ProductDescExtraNewWapper();
		Map<String, Object> prodDescMap = productDescExtraNewWapper.getByProductId(productId);

		ProductDescExtraBean productDescExtraBean = new ProductDescExtraBean();
		productDescExtraBean.setProductId(productId);
		productDescExtraBean.setDescText(prodDescMap.get("desc").toString());
		productDescExtraBean.setNoticeText(prodDescMap.get("notice") == null ? null : prodDescMap.get("notice").toString());
		productDescExtraBean.setSellerIntroText(prodDescMap.get("intro") == null ? null : prodDescMap.get("intro").toString());

		JSONArray descPicArray = new JSONArray(prodDescMap.get("descpics").toString());
		productDescExtraBean.setDescPicList(JsonBeanHelper.jsonArray2List(descPicArray, String.class));

		if (prodDescMap.get("sizepics") != null) {
			JSONArray sizepicsArray = new JSONArray(prodDescMap.get("sizepics").toString());
			productDescExtraBean.setSizePicList(JsonBeanHelper.jsonArray2List(sizepicsArray, String.class));
		}

		if (prodDescMap.get("notipics") != null) {
			JSONArray notipicsArray = new JSONArray(prodDescMap.get("notipics").toString());
			productDescExtraBean.setNoticePicList(JsonBeanHelper.jsonArray2List(notipicsArray, String.class));
		}

		if (prodDescMap.get("intropics") != null) {
			JSONArray intropicsArray = new JSONArray(prodDescMap.get("intropics").toString());
			productDescExtraBean.setSellerIntroPicList(JsonBeanHelper.jsonArray2List(intropicsArray, String.class));
		}

		if (prodDescMap.get("props") != null && new JSONArray(prodDescMap.get("props").toString()).length() > 0) {
			JSONArray propsArray = new JSONArray(prodDescMap.get("props").toString());
			List<DescPropertyBean> propertyList = new ArrayList<>();
			for (int i = 0; i < propsArray.length(); i++) {
				DescPropertyBean descPropertyBean = new DescPropertyBean();
				descPropertyBean.setKey(propsArray.getJSONObject(i).getString("key"));
				descPropertyBean.setValue(propsArray.getJSONObject(i).getString("value"));
				propertyList.add(descPropertyBean);
			}
			productDescExtraBean.setPropertyList(propertyList);
		}

		return productDescExtraBean;

	}

	public static void compareProductDescExtraBean(ProductDescExtraBean tgtProductDescExtraBean, ProductDescExtraBean actProductDescExtraBean, String desc) {

		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtProductDescExtraBean);
		tgtMap.remove("DescPicList");
		tgtMap.remove("SizePicList");
		tgtMap.remove("NoticePicList");
		tgtMap.remove("SellerIntroPicList");
		tgtMap.remove("PropertyList");

		Map<String, Object> actMap = MapUtil.pojoToMap(actProductDescExtraBean);
		actMap.remove("DescPicList");
		actMap.remove("SizePicList");
		actMap.remove("NoticePicList");
		actMap.remove("SellerIntroPicList");
		actMap.remove("PropertyList");

		AssertService.assertResultEqual(tgtMap, actMap, desc);

		// list 数据比对
		AssertService.checkArray(tgtProductDescExtraBean.getDescPicList(), actProductDescExtraBean.getDescPicList());

		if (tgtProductDescExtraBean.getSizePicList().size() != 0) {
			AssertService.checkArray(tgtProductDescExtraBean.getSizePicList(), actProductDescExtraBean.getSizePicList());
		} else {
			if (actProductDescExtraBean.getSizePicList() != null) {
				Logger.verifyEquals(0, actProductDescExtraBean.getSizePicList().size(), desc);
			}
		}

		if (tgtProductDescExtraBean.getNoticePicList() != null) {
			AssertService.checkArray(tgtProductDescExtraBean.getNoticePicList(), actProductDescExtraBean.getNoticePicList());
		} else {
			Logger.verifyIsNull(actProductDescExtraBean.getNoticePicList(), desc);
		}

		if (tgtProductDescExtraBean.getSellerIntroPicList() != null) {
			AssertService.checkArray(tgtProductDescExtraBean.getSellerIntroPicList(), actProductDescExtraBean.getSellerIntroPicList());
		} else {
			Logger.verifyIsNull(actProductDescExtraBean.getSellerIntroPicList(), desc);
		}

		if (tgtProductDescExtraBean.getPropertyList() != null) {
			tgtProductDescExtraBean.getPropertyList().forEach(ele -> {
				DescPropertyBean actBean = actProductDescExtraBean.getPropertyList().stream().filter(y -> y.getKey().equals(ele.getKey())).findFirst().orElse(null);
				Map<String, Object> tgtPropMap = MapUtil.pojoToMap(ele);
				Map<String, Object> actPropMap = MapUtil.pojoToMap(actBean);
				AssertService.assertResultEqual(tgtPropMap, actPropMap, desc);
			});
		} else {
			Logger.verifyIsNull(actProductDescExtraBean.getPropertyList(), desc);
		}

	}

	// 取秒杀商品的活动库存量 GetSecKillProductActivityStock
	// =================================================================================================================================
	public static List<SecKillProductActivityStockBean> getSecKillProductActivityStockBean(int prodInActivityId) throws Exception {
		List<SecKillProductActivityStockBean> beanList = new ArrayList<>();

		ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
		Map<String, Object> actProdMap = activityProductsWapper.getByProdInActivityId(prodInActivityId);

		JSONArray catalogs = new JSONArray(actProdMap.get("catalogs").toString());
		for (int i = 0; i < catalogs.length(); i++) {
			SecKillProductActivityStockBean bean = new SecKillProductActivityStockBean();
			bean.setActivityId(Integer.parseInt(actProdMap.get("aid").toString()));
			bean.setActivityStock(catalogs.getJSONObject(i).getInt("stock"));
			bean.setCatalogId(catalogs.getJSONObject(i).getString("cid"));
			bean.setProductActivityId(prodInActivityId);
			bean.setProductId(actProdMap.get("spid").toString());
			beanList.add(bean);
		}

		return beanList;
	}

	public static void compareSecKillProductActivityStockBean(List<String> catalgoIdList, List<SecKillProductActivityStockBean> tgtSecKillProductActivityStockBeanList,
			List<SecKillProductActivityStockBean> actSecKillProductActivityStockBeanList, String desc) {

		compareListBean(catalgoIdList, tgtSecKillProductActivityStockBeanList, actSecKillProductActivityStockBeanList, desc, (x) -> x.getCatalogId(),
				(x, y, z) -> compareSecKillProductActivityStockBean(x, y, z));

	}

	public static void compareSecKillProductActivityStockBean(SecKillProductActivityStockBean tgtSecKillProductActivityStockBean,
			SecKillProductActivityStockBean actSecKillProductActivityStockBean, String desc) {
		Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtSecKillProductActivityStockBean);
		Map<String, Object> actMap = MapUtil.pojoToMap(actSecKillProductActivityStockBean);
		AssertService.assertResultEqual(tgtMap, actMap, desc);
	}

	public static void main(String[] args) throws Exception {
//		AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(3383);
		String productId = "p1092437";
		checkTimeStampRedisAndMongo(productId);
	}

	public static ProductInDetailBean getProductInDetailBean(String productId) throws Exception {
		Thread.sleep(500);
		ProductsWapper productsWapper = new ProductsWapper();
		Map<String, Object> productMap = productsWapper.getByProductId(productId);
		Logger.debug(productMap);
		YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
		AgentProductPo agentProductPo = ymtProductsIWapper.selectAgentProductByProductId(productId);
		String rootProductId = agentProductPo.getRootProductId();
		Map<String, Object> byProductId = productsWapper.getByProductId(rootProductId);

		ProductInDetailBean productInDetailBean = new ProductInDetailBean();

		productInDetailBean.setProdId(Integer.parseInt(productMap.get("ipid").toString()));
		if (productMap.get("ver")!=null){
			productInDetailBean.setVersion(String.valueOf(Double.valueOf(productMap.get("ver").toString()) / 1000));
		}else{
            productInDetailBean.setVersion("0");
        }
		productInDetailBean.setProductId(productId);
		productInDetailBean.setTitle(productMap.get("title").toString());
		productInDetailBean.setIntroduction(productMap.get("intro") == null ? "" : productMap.get("intro").toString());
		productInDetailBean.setValidStart((Date) productMap.get("start"));
		productInDetailBean.setValidEnd((Date) productMap.get("end"));
		productInDetailBean.setSellerId(Integer.parseInt(productMap.get("sid").toString()));
		productInDetailBean.setSellerName(productMap.get("sname").toString());

		productInDetailBean.setBrandId(Integer.parseInt(byProductId.get("bid").toString()));
		productInDetailBean.setBrandName(byProductId.get("brand").toString());

		productInDetailBean.setBrandEnName(byProductId.get("ebrand").toString());
		productInDetailBean.setMasterCategoryId(Integer.parseInt(byProductId.get("mcatid").toString()));
		productInDetailBean.setMasterCategoryName(byProductId.get("mcatname").toString());
		productInDetailBean.setCategoryId(Integer.parseInt(byProductId.get("scatid").toString()));

		productInDetailBean.setCategoryName(byProductId.get("scatname").toString());
		productInDetailBean.setThirdCategoryId(Integer.parseInt(byProductId.get("tcatid").toString()));
		productInDetailBean.setThirdCategoryName(byProductId.get("tcatname").toString());
		productInDetailBean.setCatalogType(Integer.parseInt(productMap.get("ctype").toString()));
		productInDetailBean.setDeliveryMethod(Integer.parseInt(byProductId.get("deliv").toString()));
		productInDetailBean.setBondedArea(Integer.parseInt(productMap.get("bonded").toString()));
		productInDetailBean.setTariffType(Integer.parseInt(productMap.get("tariffy").toString()));
		productInDetailBean.setIsFreeShipping(Double.parseDouble(productMap.get("shipping").toString()) <= 0);
		productInDetailBean.setCountryId(Integer.parseInt(productMap.get("country").toString()));
		productInDetailBean.setAddTime((Date) productMap.get("addtime"));
		productInDetailBean.setLocalReturn(Integer.parseInt(productMap.get("localr").toString()));
		productInDetailBean.setNoticeRisk(Boolean.parseBoolean(productMap.get("risk").toString()));
		productInDetailBean.setProductCode(productMap.get("pcode") == null ? "" : productMap.get("pcode").toString());
		productInDetailBean.setNoReasonReturn(Boolean.parseBoolean(productMap.get("noreason").toString()));
		productInDetailBean.setGiftType(0);
		productInDetailBean.setSizePicList(new ArrayList<>());
		productInDetailBean
				.setIsNewProduct(getNewestProduct(Boolean.parseBoolean(productMap.get("isnew").toString()), (Date) productMap.get("newstart"), (Date) productMap.get("newend")));

		productInDetailBean.setNewStartTime((Date) productMap.get("newstart"));
		productInDetailBean.setNewEndTime((Date) productMap.get("newend"));
		productInDetailBean.setIsHotRecmd(Boolean.parseBoolean(productMap.get("istop").toString()));
		productInDetailBean.setIsPspProduct(Boolean.parseBoolean(productMap.get("ispsp").toString()));
		productInDetailBean.setGrade(productMap.get("grade").toString());
		productInDetailBean.setHasTextDescription(Boolean.parseBoolean(productMap.get("newdesc").toString()));
		productInDetailBean.setGrouponVersion(0);

		productInDetailBean.setRootUserId(Integer.parseInt(productMap.get("ruid").toString()));
		productInDetailBean.setParentUserId(Integer.parseInt(productMap.get("puid").toString()));
		productInDetailBean.setCardInfo(Integer.parseInt(productMap.get("card").toString()));
		productInDetailBean.setAgentChain(productMap.get("achain").toString());

		List<DeliveryTemplateDto> deliveryTemplateList = new ArrayList<>();
		if (ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootProductId)!=null){
			List<Map> deliMaps = ymtProductsIWapper.getProductDeliveryTemplateByProdId(rootProductId);
			deliMaps.forEach(p->{
				DeliveryTemplateDto deliveryTemplateDto = new DeliveryTemplateDto();
				deliveryTemplateDto.setDeliveryMethod(Integer.parseInt(byProductId.get("deliv").toString()));
				deliveryTemplateDto.setTemplateId(Integer.parseInt(p.get("TemplateId").toString()));
				deliveryTemplateList.add(deliveryTemplateDto);
			});
		}
		productInDetailBean.setDeliveryTemplateList(deliveryTemplateList);

		//商品类型(0- C2C商品，1- 全球优选商品 3-微信代购商品)
		productInDetailBean.setProductType(Integer.parseInt(productMap.get("ptype").toString()));
		//礼包类型(0- 非礼包，1- 礼包商品)
		if (Integer.parseInt(productMap.get("gtype").toString())==1){
			productInDetailBean.setGiftType(1);
		}else{
			productInDetailBean.setGiftType(0);
		}

		productInDetailBean.setGlobalProductType(Integer.parseInt(productMap.get("gtype").toString()));

		// pic list
		List<String> picList = new ArrayList<>();
		if (productMap.get("pics") != null) {
			JSONArray jsonArray = new JSONArray(productMap.get("pics").toString());
			for (int i = 0; i < jsonArray.length(); i++) {
				picList.add(jsonArray.getString(i));
			}
		}
		productInDetailBean.setPicList(picList);
		if (agentProductPo.getInfoProgress()==-2||agentProductPo.getInfoProgress()==-1){
			productInDetailBean.setStatus(2);
		}else{
			if (Integer.parseInt(productMap.get("status").toString())==1){
				productInDetailBean.setStatus(0);
			}else if (Integer.parseInt(productMap.get("status").toString())==2){
				productInDetailBean.setStatus(2);
			}
		}


		productInDetailBean.setOwnProduct(Integer.parseInt(productMap.get("own").toString()) == 1 ? true : false);
		productInDetailBean.setExtraDeliveryType(Integer.parseInt(productMap.get("mdeliv").toString()));
		productInDetailBean.setExtraDeliveryFee(Double.parseDouble(productMap.get("mflight").toString()));
		List<CatalogInDetailBean> CatalogInDetailBeanList = new ArrayList<>();

		CatalogsWapper catalogsWapper = new CatalogsWapper();
		List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());

		List<Map<String, Object>> catalogMapList = new ArrayList<>();
		catalogs.forEach(ele -> {
			try {
				catalogMapList.add(catalogsWapper.getByCatalogId(ele));
			} catch (Exception e) {
				e.printStackTrace();
			}
		});

		for (int i = 0; i < catalogMapList.size(); i++) {
			Map<String, Object> catalogMap = catalogMapList.get(i);
			String catalogId = catalogMap.get("cid").toString();

			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			YmtCatalogsI ymtCatalogsI = ymtCatalogsIWapper.selectCatalogsByCatalogId(ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId).getRootCatalogId());

			CatalogInDetailBean catalogInDetailBean = new CatalogInDetailBean();
			catalogInDetailBean.setCatalogId(catalogId);
			catalogInDetailBean.setSKU(String.valueOf(catalogMap.get("sku") == null ? "" : catalogMap.get("sku").toString()));
			catalogInDetailBean.setIsPreSale(Boolean.parseBoolean(catalogMap.get("presale").toString()));
			catalogInDetailBean.setPrice(Double.parseDouble(catalogMap.get("price").toString()));
			catalogInDetailBean.setNewGuestPrice(Double.parseDouble(catalogMap.get("newp").toString()));
			catalogInDetailBean.setVipPrice(Double.parseDouble(catalogMap.get("vip").toString()));
			catalogInDetailBean.setCatalogStock(ymtCatalogsI.getiNum());
			catalogInDetailBean.setCommission(Double.parseDouble(catalogMap.get("commission").toString()));
			catalogInDetailBean.setMarketPrice(Double.parseDouble(catalogMap.get("mprice").toString()));
			catalogInDetailBean.setWeight(ymtCatalogsI.getWeight().doubleValue());
			catalogInDetailBean.setNextActivityPrice(0.0);
			if (catalogMap.get("catapic")!=null){
                catalogInDetailBean.setPicUrl(catalogMap.get("catapic").toString());
            }else{
			    catalogInDetailBean.setPicUrl(null);
            }
			Map<String, Object> map = catalogsWapper.getByCatalogId(catalogId);
			catalogInDetailBean.setGrouponPrice(0.0);
			List<CatalogPropsInDetailBean> properties = new ArrayList<>();
			if (catalogMap.get("props") == null) {
				// 添加一个空的
				CatalogPropsInDetailBean catalogPropsInDetailBean = new CatalogPropsInDetailBean();
				properties.add(catalogPropsInDetailBean);
			} else {
				JSONArray propsAry = new JSONArray(catalogMap.get("props").toString());
				for (int j = 0; j < propsAry.length(); j++) {
					JSONObject prop = propsAry.getJSONObject(j);
					CatalogPropsInDetailBean catalogPropsInDetailBean = new CatalogPropsInDetailBean();
					catalogPropsInDetailBean.setName(prop.getString("name"));
					catalogPropsInDetailBean.setValue(prop.getString("value"));
					catalogPropsInDetailBean.setPicUrl(prop.getString("pic"));
					properties.add(catalogPropsInDetailBean);
				}
			}
			catalogInDetailBean.setPropertyList(properties);
			catalogInDetailBean.setActivityPrice(0d);
			catalogInDetailBean.setActivityStock(0);
			catalogInDetailBean.setIsInActivity(false);
			CatalogInDetailBeanList.add(catalogInDetailBean);
		}
		productInDetailBean.setCatalogList(CatalogInDetailBeanList);
		Logger.debug("productInDetailBean:"+productInDetailBean);
		return productInDetailBean;
	}
}
